CodeForces - 573A Bear and Poker
2017-02-23 20:34
351 查看
这道题确实是自己太蠢
每个数通过双倍或者三倍 能否达到同一个数
当时一直想用LCM/a[i]后来除以2 除以3看最后是否为1
然后一直WA On test49
当然知道是数据爆了 然后就卡住了
想想如果这n个数能够乘2 乘3 得到同一个数说明 这些数的约数 只在2 和 3的数量上不同 其他约数都应该是相同的
那么 就按除法 每个数 除以2 除以3 看剩下的约数是否相同 即可
1 #include <iostream> 2 #include <stdio.h> 3 #include <string> 4 #include <string.h> 5 #include <map> 6 #include <fstream> 7 #include <set> 8 #define READ() freopen("in.txt", "r", stdin); 9 using namespace std; 10 11 12 long long gcd(long long a, long long b) 13 { 14 if (b == 0) return a; 15 else return gcd(b, a%b); 16 } 17 18 long long a[100007]; 19 int main() 20 { 21 READ() 22 int n; 23 set<int> s; 24 long long LCM, old_LCM, time; 25 scanf("%d", &n); 26 for (int i = 0; i < n; i++) 27 { 28 scanf("%lld", &a[i]); 29 }//求得最小公倍数 30 for (int i = 0; i < n; i++) //判断是否成功 31 { 32 while (!(a[i] % 2)) a[i] /= 2; 33 while (!(a[i] % 3)) a[i] /= 3; 34 s.insert(a[i]); 35 } 36 if (s.size() == 1 ) printf("Yes\n"); 37 else printf("No\n"); 38 return 0; 39 }
相关文章推荐
- CodeForces_1A
- Number of Ways--CodeForces 466C 水题
- codeforces-611D-New Year and Ancient Prophecy【lcp+dp】【好题】
- Codeforces刷题之路——467A George and Accommodation
- CodeForces - 731C Socks(并查集)(贪心)
- CodeForces 788B 浅谈并查集维护奇妙欧拉回路
- Codeforces 931.F Teodor is not a liar!
- codeforces 159D dp + strings 好题
- CodeForces - 44B Cola
- Codeforces--14D--Two Paths(树的直径)
- [Codeforces 585C] Alice, Bob, Oranges and Apples (Stern-Brocot Tree + 更相减损法)
- CodeForces 779E Bitwise Formula
- CodeForces 303 A.Lucky Permutation Triple(构造)
- Codeforces 931C Laboratory Work
- codeforces 俄罗斯季度决赛题目sequence解答
- Codeforces 124B. Permutations
- codeforces_628C. Bear and String Distance
- codeforces 699 B. One Bomb (思维)
- CodeForces - 540A A. Combination Lock
- Codeforces 844 C Sorting by Subsequences(离散+dfs+排序)