http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770
这是这次BSG白山极客挑战赛的A题。由于数字全部相同,乘上b必然会有循环节,于是模拟乘法,记录数据,出现循环就退出即可。
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include <set> #include <map> #include <queue> #include <vector> #include <string> #define LL long long using namespace std; int a, b, d, n; int main() { //freopen("test.in", "r", stdin); int T, rest, to, pre; scanf("%d", &T); for (int times = 0; times < T; ++times) { int ans = 0, tmp; scanf("%d%d%d%d", &a, &b, &d, &n); rest = to = 0; pre = -1; for (int i = 0; i < n; ++i) { tmp = a*b+to; to = tmp/10; rest = tmp%10; if (tmp == pre) { if (rest == d) ans += n-i; break; } pre = tmp; if (rest == d) ans++; } if (to != 0 && to == d) ans++; printf("%d\n", ans); } return 0; }
时间: 2024-11-10 11:31:37