Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
2017-08-15 21:31
531 查看
/** * Codeforces * Problem#833A * Accepted * Time: 218ms * Memory: 2052k */ #include <bits/stdc++.h> using namespace std; typedef bool boolean; #define LL long long int sqrt3(LL x) { int l = 1, r = 1e6; while(l <= r) { LL mid = (l + r) >> 1; if(mid * mid * mid <= x) l = mid + 1; else r = mid - 1; } return l - 1; } int a, b; long long P; inline void init() { scanf("%d%d", &a, &b); P = a * 1LL * b; } inline boolean solve() { long long x = sqrt3(P); if(x * x * x != P) return false; return !(a % x || b % x); } int T; int main() { scanf("%d", &T); while(T--) { init(); puts(solve() ? ("Yes") : ("No")); } return 0; }
The Meaningless Game(Binary Search)
最后写了一个可以用Hash的二分法(Excuse me?新型long long开方向下取整?)
Code
/** * Codeforces * Problem#833A * Accepted * Time: 233ms * Memory: 9900k */ #include <bits/stdc++.h> using namespace std; typedef bool boolean; #define LL long long const int limit = 1e6; LL arr3[limit + 1]; inline void rinit() { for(int i = 1; i <= limit; i++) arr3[i] = i * 1LL * i * i; } int a, b; long long P; inline void init() { scanf("%d%d", &a, &b); P = a * 1LL * b; } inline boolean solve() { int x = lower_bound(arr3 + 1, arr3 + limit + 1, P) - arr3; if(arr3[x] != P) return false; return !(a % x || b % x); } int T; int main() { rinit(); scanf("%d", &T); while(T--) { init(); puts(solve() ? ("Yes") : ("No")); } return 0; }
相关文章推荐
- CodeForces 399C Cards (数论)
- CodeForces 558C Amr and Chemistry (位运算,数论,规律,枚举)
- codeforces 487C C. Prefix Product Sequence(构造+数论)
- Codeforces 711E 数论
- Codeforces 413B Spyke Chatting(数论简单)
- 关于使用牛顿迭代法和二分法解方程的算法说明
- CodeForces 300C C. Beautiful Numbers (数论 + 逆元 + 详解)
- CodeForces - 376C Divisible by Seven(数论:同余定理)(找规律)
- CodeForces - 359C Prime Number(数论)
- CodeForces - 58B Coins(数论)
- CodeForces 633 B.A Trivial Problem(二分+数论)
- Codeforces 584D Dima and Lisa(数论)
- codeforces 475D CGCDSSQ (st表+数论)
- CodeForces 346A Alice and Bob(数论)
- Codeforces 603B - Moodular Arithmetic 数论 应用群的基本性质
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
- Codeforces 757B Bash's Big Day 【数论】
- Codeforces 264B 数论+DP
- CodeForces 584D - Dima and Lisa(数论)
- CodeForces 449 C.Jzzhu and Apples(构造+数论)