CodeForce #318 div 2 C Bear and Poker
2015-09-24 21:02
357 查看
很简单的题目啊。。
结果我还真的求了n次最小公倍数。其实只用求除了2和3以外的公因数乘积是不是想等就可以啦。
然而时间差别并不大。
结果我还真的求了n次最小公倍数。其实只用求除了2和3以外的公因数乘积是不是想等就可以啦。
#include<cstring> #include<algorithm> #include<queue> #include<cstdio> #include<iostream> using namespace std; int n,st,en; int gcd(int a, int b) { int tmp = a; if(a<b) { a = b; b = tmp; } while(b!=0) { tmp = a%b; a = b; b = tmp; } return a; } bool check(int a, int b) { int c = gcd(a,b); int x1 = a/c, x2 = b/c; while(x1>1){ if(x1%2==0) x1/=2; else if(x1%3==0) x1/=3; else return false; } while(x2>1){ if(x2%2==0) x2/=2; else if(x2%3==0) x2/=3; else return false; } return true; } int main() { cin>>n>>st; int g; bool find = false; for(int i = 1; i< n; i++) { cin>>en; if(!check(st,en)){ find = true; break; } } if(find) cout<<"No"; else cout<<"Yes"; return 0; }
然而时间差别并不大。
#include<cstring> #include<algorithm> #include<queue> #include<cstdio> #include<iostream> using namespace std; int n,st,en; int resi(int x) { while(x%2 == 0) x/=2; while(x%3 == 0) x/=3; return x; } int main() { cin>>n>>st; int g; bool find = false; g = resi(st); for(int i = 1; i< n; i++) { cin>>en; if(g!=resi(en)){ find = true; break; } } if(find) cout<<"No"; else cout<<"Yes"; return 0; }
相关文章推荐
- 后台程序
- Android Api Demos登顶之路(八十)Graphics-->PathFillTypes
- Cocos2d-x 手机游戏《疯狂的蝌蚪》资源 “开源” win32+安德鲁斯+iOS三合一
- Java基础知识强化70:正则表达式之引入案例(QQ号码校验)
- [sicily]1813. M进制数问题
- HDU - 1864 最大报销额(01背包)
- 汉诺塔
- More Effective C++ 条款20 协助完成"返回值优化(RVO)"
- 百度offe面经及找工作一个月体会
- TCP/IP的工作方式
- VMware10上CentOS6.5安装MySQL2.6.26
- THU数据结构编程作业一:查询范围(Range)
- (更新)OutputDebugString函数简单封装,实现格式化打印输出(VC++)
- POJ3984
- Android所遇到的问题归类
- 怎么给qt程序添加版本信息
- Redis 命令 - Hashs
- ServletContextListener
- PHP 执行系统外部命令 system() exec() passthru()
- 关于iOS国际化(根据手机App用户自己来切换语言) App支持多语言切换