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 = ; times < T; ++times)
{
int ans = , tmp;
scanf("%d%d%d%d", &a, &b, &d, &n);
rest = to = ;
pre = -;
for (int i = ; i < n; ++i)
{
tmp = a*b+to;
to = tmp/;
rest = tmp%;
if (tmp == pre)
{
if (rest == d) ans += n-i;
break;
}
pre = tmp;
if (rest == d) ans++;
}
if (to != && to == d) ans++;
printf("%d\n", ans);
}
return ;
}