Codeforces Round #276 (Div. 2)A. Factory(数论)
这道题可以暴力的一直按要求的方法去做,做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(数论)的更多相关文章
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #276 (Div. 2)
A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...
- Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- 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 ...
- 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 ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- 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的数 维护 ...
随机推荐
- Python学习笔记2_Python基础
一.变量(给数据起个名字) 变量是计算机内存中的一块区域,变量可以存储规定范围内的值,而且值可以改变. 1.变量的命名方法 -变量名有字母.数字.下划线组成 -不能以数字开头 -不可以使用关键字 -a ...
- Verilog HDL设计规范及经验谈(转载)
1. 规范很重要 工作过的朋友肯定知道,公司里是很强调规范的,特别是对于大的设计(无论软件还是硬件),不按照规范走几乎是不可实现的.逻辑设计也是这样:如果不按规范做的话,过一个月后调试时发现 ...
- 算法题14 小Q歌单,牛客网,腾讯笔试题
算法题14 小Q歌单,牛客网,腾讯笔试题 题目: 小Q有X首长度为A的不同的歌和Y首长度为B的不同的歌,现在小Q想用这些歌组成一个总长度正好为K的歌单,每首歌最多只能在歌单中出现一次,在不考虑歌单内歌 ...
- active admin
activeadmin 1.0.0.pre4 所依赖的库 gem 'jquery-rails', '~> 4.0.4' 4.2版本会出现找不到jquery-ui 的datepicker错误 使用 ...
- docker-compose no such image
是由于docker-compose旧缓存的问题,执行docker-compose down即可,再重新up
- Django 补充models操作,中间件, 缓存,信号,分页
1.Model 一对多 补充 models如下: class UserType(models.Model): caption = models.CharField(max_length=16) cla ...
- awk的内置函数
常见awk内置数值函数
- 基于SSM的单点登陆02
pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- java 程序的使用
Java程序可以在任何安装有Java平台的系统上运行,运行的时候语法如下: java -jar <program.jar> -jar这个参数是必须有的,后面跟你的java程序,例如我们 ...
- java基础之final/static/static final
一.final 1.final修饰变量(常量) final修饰的成员变量表示常量,一旦给定初值既无法改变 2.final方法 final修饰方法,表示该方法不能被子类重写 好处:比非final方法要快 ...