当前位置:首页 > 编程笔记 > 正文
已解决

Jellyfish and Green Apple-Codeforces Round 902 (Div. 2)

来自网友在路上 172872提问 提问时间:2023-10-21 17:49:40阅读次数: 72

最佳答案 问答题库728位专家为你答疑解惑

Jellyfish and Green Apple

最小切几刀分苹果
判断-1的条件是最小公倍数/m不是2的倍数,那么苹果不能被一刀切成两块

#include<iostream>
#define int long long
using namespace std;
int gcd(int a, int b)
{if (b == 0)return a;return gcd(b, a % b);
}
signed main()
{int T;cin>>T;while(T--){int n,m;cin>>n>>m;if(n%m==0){cout<<0<<endl;}else{int M=m/gcd(n,m),f=0;while(M>1){//判断能不能切if(M&1){f=1;break;}M/=2;}if(f==1) {cout<<-1<<endl;continue;}n%=m;//可以切,计算最小切的次数int ans=n;while(n%m){n*=2;n%=m;ans+=n;}cout<<ans<<endl;}}
}
查看全文

99%的人还看了

相似问题

猜你感兴趣

版权申明

本文"Jellyfish and Green Apple-Codeforces Round 902 (Div. 2)":http://eshow365.cn/6-20953-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!