Codeforces Round #834 (Div. 3) D. Make It Round
Problem - D - Codeforces
Code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=1e3+10,mod=998244353;
int n,m,cnt1=0,cnt2=0;
void solve(){
cnt1=0,cnt2=0;
cin>>n>>m;
int t=n;
while(n%2==0){
cnt1++;
n/=2;
}
while(n%5==0){
cnt2++;
n/=5;
}
int k=1;
while(cnt1<cnt2&&k*2<=m) k*=2,cnt1++;
while(cnt2<cnt1&&k*5<=m) k*=5,cnt2++;
while(k*10<=m) k*=10;
int h=m/k;
k*=h;
cout<<t*k<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
还没有评论,来说两句吧...