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 ;
}

最新文章

  1. [OSG]矩阵运算
  2. 使用VS Code 开发.NET Core 应用程序 部署到Linux 跨平台
  3. 两种方法获取shadow ssdt
  4. unity mathf.repeat 截取操作
  5. raw格式镜像文件压缩并转换为qcow2格式
  6. 在css中定义滚动条样式
  7. class打包成exe方式
  8. hdu 2473 Junk-Mail Filter (并查集之点的删除)
  9. OpenCV 2.4.9
  10. Mysql中的 的 Cascade ,NO ACTION ,Restrict ,SET NULL
  11. 用Total Commander替换windos默认资源管理器
  12. neu1458 方格取数 dp解法
  13. JDK1.8下载与安装及环境变量配置
  14. [dev][ipsec] netlink是什么
  15. Incorrect username or password ( access token )解决
  16. 搭建git 服务器
  17. Prepare paddle in Docker1
  18. chrome版本与对应的chromedriver驱动【转载】
  19. Python2.7-zlib
  20. python操作txt文件中数据教程[2]-python提取txt文件

热门文章

  1. NFS 安装、管理
  2. Book Review of “The practice of programming” (Ⅱ)
  3. &lt;关于并发框架&gt;Java原生线程池原理及Guava与之的补充
  4. 用WAR的方式部署SpringBoot项目
  5. Spring Boot 快速入门(IDEA)
  6. idea开启springboot的devtools自动热部署功能
  7. Parameter Binding in ASP.NET Web API
  8. windchill系统——开发_角色管理——增加角色
  9. scala学习手记40 - 使用case类
  10. 四十九 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)用Django实现搜索结果分页