这道题可以暴力的一直按要求的方法去做,做1000000次还不能整除m就认为永远不能整除m了(m不超过100000,循环1000000次比较安全了已经)。这种方法可以AC。

下面深入的分析一下到底循环多少次就可以确定结果:首先有这样一个规律:(a+b)%c=(a%c+b%c)%c,那么这样其实这道题每次就是2*a。官方题解说的好:

Production will stops iff exists integer K ≥ 0 such a·2K is divisible by m. From this fact follows that K maximum will be about O(log2(m)). So if we modeling some, for example, 20 days and production does not stop, then it will never stop and answer is "No". Otherwise answer is "Yes".

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+; int a,m;
int main()
{
//freopen("in8.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d%d",&a,&m);int w=;
for(int i=;i<;i++)
{
if(a%m==){w=;puts("Yes");break;}
a%=m;
a+=a;
}
if(w==)puts("No");
//fclose(stdin);
//fclose(stdout);
return ;
}

或者不这么想也行,就去找周期性的规律也可以,但是注意周期不一定从第一个数开始,其实只要后面的a%m有在前面出现过了,那就不用再算下去了,肯定后面都一样。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
int a,m;
set<int>s;
int main()
{
cin>>a>>m;
while(a%m!=){
if(s.find(a%m)!=s.end()){cout<<"No"<<endl; return ;}
s.insert(a%m);
a += (a%m);
}
cout<<"Yes"<<endl; return ;
}

Codeforces Round #276 (Div. 2)A. Factory(数论)的更多相关文章

  1. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  2. Codeforces Round #276 (Div. 2)

    A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...

  3. Codeforces Round #338 (Div. 2) D. Multipliers 数论

    D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...

  4. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  5. Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数

    B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...

  6. Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心

    A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...

  7. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

  8. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  9. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

随机推荐

  1. More about Parameter Passing in Python(Mainly about list)

    我之前写了一篇关于Python参数传递(http://www.cnblogs.com/lxw0109/p/python_parameter_passing.html)的博客, 写完之后,我发现我在使用 ...

  2. C# Ajax 技术

    Ajax 是 Asynchronous JavaScript and XML(以及 DHTML 等)的缩写.下面是 Ajax 应用程序所用到的基本技术:• HTML 用于建立 Web 表单并确定应用程 ...

  3. python常用模块——os模块

    python编程时,经常和文件.目录打交道,这就离不开os模块,os模块包含普遍的操作系统功能,与具体的平台无关,列举一些常用的命令. 1.os.name:字符串指示你正在使用的平台.windows是 ...

  4. Python基础(18)_面向对象程序设计2(反射、__str__、__del__、__item__系列)

    一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo(object) ...

  5. docker devise相关错误

    rake aborted!Devise.secret_key was not set. Please add the following to your Devise initializer: con ...

  6. ES集群性能调优链接汇总

    1. 集群稳定性的一些问题(一定量数据后集群变得迟钝) https://elasticsearch.cn/question/84 2. ELK 性能(2) — 如何在大业务量下保持 Elasticse ...

  7. 何为RunLoop?RunLoop有哪些应用场景?

    一.RunLoop的作用 一个应用开始运行以后放在那里,如果不对它进行任何操作,这个应用就像静止了一样,不会自发的有任何动作发生,但是如果我们点击界面上的一个按钮,这个时候就会有对应的按钮响应事件发生 ...

  8. iOS_核心动画(二)

    目 录: 一.Core Animation开发步骤 二.Core Animation的继承结构 三.CAAnimation常用的属性 四.CAPropertyAnimation(属性动画) 五.CAB ...

  9. linux输入子系统简述【转】

    本文转载自:http://blog.csdn.net/xubin341719/article/details/7678035 1,linux输入子系统简述 其实驱动这部分大多还是转载别人的,linux ...

  10. 淘宝分类常见---部分显示和全部显示的js效果

    需求就是,点击“更多按钮”,显示全部的分类详情,再次点击,显示部分分类. 展开: 收起: 结构: <div class="SubBox" id="SubBox&qu ...