Codeforces Round #426 (Div. 2)C. The Meaningless Game

题意:AB两个人,每一轮,其中一人选择一个数字K,那么A就变成A*k*k,B就变成B*K,给出结果,问是否可能

思路:不管多少轮,A*B结果都是某个数的立方,二分



 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N=1e5+10,M=1e6+10,inf=1e9+7,MOD=1e9+7;
 5 const ll INF=1e18+10,mod=1e9+7;
 6
 7
 8 int main()
 9 {
10     int T;
11     scanf("%d",&T);
12     while(T--)
13     {
14         ll a,b;
15        scanf("%lld%lld",&a,&b);
16        ll l=1,r=1e6+10,ans=-1;
17         while(l<=r)
18         {
19             ll mid=(l+r)/2;
20             if(mid*mid*mid<=a*b)
21             {
22                 ans=mid;
23                 l=mid+1;
24             }
25             else r=mid-1;
26         }
27         if(ans*ans*ans==a*b&&a%ans==0&&b%ans==0)printf("Yes\n");
28         else printf("No\n");
29     }
30     return 0;
31 }

				
时间: 2024-08-09 13:06:48

Codeforces Round #426 (Div. 2)C. The Meaningless Game的相关文章

Codeforces Round #426 (Div. 2) C. The Meaningless Game (二分 or pow函数)

Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it fast

Codeforces Round #426 (Div. 1) A.The Meaningless Game (二分+数学)

题目链接: http://codeforces.com/problemset/problem/833/A 题意: 给你 \(a\) 和 \(b\),两个人初始化为 \(1\).两个人其中一方乘以 \(k^2\),另一方就乘以 \(k\).问你能不能达到 \((a,b)\) 这个最终状态. 题解: 设 \(X\), \(P\) 表示两个乘积的集合. 那么,显然: \(S^{2}*P=a\) ------ 1 \(S*P^{2}=b\) ------ 2 所以:\(a*b = S^{3}*P^3\)

Codeforces Round #426 (Div. 2) D. The Bakery(线段树维护dp)

题目链接: Codeforces Round #426 (Div. 2) D. The Bakery 题意: 给你n个数,划分为k段,每段的价值为这一段不同的数的个数,问如何划分,使得价值最大. 题解: 考虑dp[i][j]表示划分为前j个数划分为i段的最大价值,那么这就是一个n*n*k的dp, 考虑转移方程dp[i][j]=max{dp[i][k]+val[k+1][j]},我们用线段树去维护这个max,线段树上每个节点维护的值是dp[i][k]+val[k+1][j],对于每加进来的一个数a

Codeforces Round #426 (Div. 2)A B C题+赛后小结

最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络赛,我似乎都没用上新学的东西,能用上新学东西的题我A不了...5555555555555555 这场CF,讲真,打的心态爆炸,首先A题无限WA,赛后看下WA的那组数据是输入有一个999999999的样例,死骗子,说好的数据是1e9呢,哪能有数据是1e10-1,于是用long long,一下子Accept接收不

Codeforces Round #426 (Div. 2) (A B C)

A. The Useless Toy Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strang

Codeforces Round #426 (Div. 1) (ABCDE)

1. 833A The Meaningless Game 大意: 初始分数为$1$, 每轮选一个$k$, 赢的人乘$k^2$, 输的人乘$k$, 给定最终分数, 求判断是否成立. 判断一下$a\cdot b$是否是立方数, 以及能否被那个立方的因子整除即可. cbrt竟然有误差, 特判了一下, 好坑 #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #i

codeforces round #426 div 2

A: 如果n%2=0或2就是undefined,否则判一下转一下是否能到达状态 #include<bits/stdc++.h> using namespace std; int n; char s[10], t[10]; int main() { scanf("%s%s%d", s, t, &n); if(n % 4 == 0 || n % 4 == 2) { puts("undefined"); return 0; } if((s[0] ==

Codeforces Round #426 (Div. 2)A. The Useless Toy

题意:4个箭头,给出起始箭头,终始箭头,问经历n次,是由顺时针cw得到,还是逆时针cww得到,如果都可以输出undefined 思路:n%4,就是次数了,再两个方向模拟下 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=1e5+10; 5 6 int a[6]={0,1,2,3,4}; 7 int main(){ 8 int n; 9 char s1[2],s2[2];

Codeforces Round #426 (Div. 2)B. The Festive Evening

题意:有26个城门,k个守卫,给出每个城门人进入的顺序,只有当这个城门进入的人是最后一个,该城门的守卫才能去别的城门,问是否有个时间段,守卫不够用 思路:记录起始,模拟下 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int l[30],r[30]; 5 int b[30]; 6 7 int main(){ 8 int n,m; string s; 9 cin>>n>>m; 10 cin>>s; 1