Codeforces - 834C. The Meaningless Game - 数学
2017-08-01 23:26
363 查看
C. The Meaningless Game
题目链接分类:数学
1.题目描述
有n(1≤n≤350000)场游戏,对于每场游戏有若干个回合组成,两个人的初始分均为1,每个回合赢的人当前分数乘上k2,输的人当前分数乘上k(每一回合的k都是不同的)。给你两个数a,b(1≤a,b≤109)问你这两个数是否为他们最终的分数?2.解题思路
显然我们容易发现最终状态是a=k21k2, b=k1k22的形式,我们考虑把两者相乘就有ab=k31k32,要保证合法,也就是k1k2=ab−−√3,即ab必须能被开三次方!第一种做法:我们去枚举或者二分i3或者来判断是否存在ab=i3x成立,存在即合法。
[b]第二种做法:直接暴力开三次根号,根据计算机舍入规则判断是否合法(不推荐)。
3.AC代码
第一种做法:ll t[maxn]; void init() { for(int i = 0; i <= 1000000; i++) t[i] = (ll)i * i * i; } int main() { init(); int n, a, b; scanf("%d", &n); while(n--) { scanf("%d%d", &a, &b); ll c = (ll)a * b; int pos = lower_bound(t, t + maxn, c) - t; //printf("pos=%d\n",pos); if((ll)pos * pos * pos == c && a % pos == 0 && b % pos == 0) printf("Yes\n"); else printf("No\n"); } return 0; }
第二种做法:
#include <bits/stdc++.h> using namespace std; #define lson root << 1 #define rson root << 1 | 1 #define lent (t[root].r - t[root].l + 1) #define lenl (t[lson].r - t[lson].l + 1) #define lenr (t[rson].r - t[rson].l + 1) #define eps 1e-6 #define e exp(1.0) #define pi acos(-1.0) #define fi first #define se second #define pb push_back #define mp make_pair #define SZ(x) ((int)(x).size()) #define All(x) (x).begin(),(x).end() #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define Close() ios::sync_with_stdio(0),cin.tie(0) #define INF 0x3f3f3f3f #define maxn 100010 #define N 1111 typedef vector<int> VI; typedef pair<int, int> PII; typedef long long ll; typedef unsigned long long ull; const int mod = 1e9 + 7; /* head */ int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); long _begin_time = clock(); #endif int t; ll a, b; scanf("%d", &t); while(t--) { scanf("%lld%lld", &a, &b); ll temp = ceil(pow(a * b * 1.0, 1.0 / 3)); if(temp * temp * temp != a * b || a % temp || b % temp) { puts("No"); } else { puts("Yes"); } } #ifndef ONLINE_JUDGE long _end_time = clock(); printf("time = %ld ms.", _end_time - _begin_time); #endif return 0; }
相关文章推荐
- CodeForces - 834C. The Meaningless Game
- (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
- CodeForces - 834C The Meaningless Game
- codeforces 834C (The Meaningless Game)
- codeforces The Meaningless Game 数学思维
- J - The Meaningless Game CodeForces - 834C
- codeforces 834 C The Meaningless Game
- (数学或二分)Codeforces Round #426 C. The Meaningless Game
- CodeForces 834 C. The Meaningless Game
- (CodeForces 883A) The Meaningless Game 二分答案思路+骚操作
- Codeforces 834(426 Div.2) C.The Meaningless Game
- CodeForces 833 A.The Meaningless Game(水~)
- codeforces 834 C The Meaningless Game
- 【CodeForces】426Div2 C The Meaningless Game
- Codeforces Round #426 (Div. 2)The Meaningless Game【数学题】【水题】
- Codeforces 833A-The Meaningless Game
- Codeforces 834 C The Meaningless Game(二分)
- 【数学分析】Codeforces Round #426(Div.2)C[The Meaningless Game]题解
- The Meaningless Game 【codeforces】【思维】