Codeforces 1525A.Potion-making

题意描述:每次能向锅里添加1份魔法精华或者1份水,问最少几次操作能让锅里精华比例为k%

朴素的想,往里放入k份精华和100-k份水。
然后发现可以约分,约分完了加起来,最终答案为100/gcd(k,100-k).

```
#include<bits stdc++.h>
#define ll long long
using namespace std;
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int x=n,y=100-n,z=gcd(x,y);
cout<<100/z<

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务