A. k-rounding
time limit per test1 second
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the k-rounding of n.
Input
The only line contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 8).
Output
Print the k-rounding of n.
Examples
Input
375 4
Output
30000
Input
10000 1
Output
10000
Input
38101 0
Output
38101
Input
123456789 8
Output
12345678900000000
题意:…..
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e5+10;
const double eps=1e-6;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
ll num,k;
cin>>num>>k;
ll maxx=num;
for(int i=1;i<=k;i++) maxx=maxx*10;
int flag=0;
if((num%10)==9||(num%10)==3||(num%10)==7||(num%10)==1||num==1){
cout<<maxx<<endl;
return 0;
}
for(ll i=1;;i++){
if(((num%10)*i)%10!=0)
continue;
ll temp=num*i;
ll t=temp;
if(temp>maxx)
break;
int cnt=0;
while(temp%10==0){
cnt++;
temp=temp/10;
}
if(cnt>=k){
flag=1;
cout<<t<<endl;
break;
}
}
if(!flag) cout<<maxx<<endl;
return 0;
}
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e5+10;
const double eps=1e-6;
ll gcd(ll a,ll b){
return (!b)?a:gcd(b,a%b);
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
ll num,k;
ll temp=1;
cin>>num>>k;
for(int i=1;i<=k;i++) temp*=10;
cout<<num/gcd(num,temp)*temp<<endl;
return 0;
}
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e5+10;
const double eps=1e-6;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
ll num,k;
cin>>num>>k;
ll temp=1;
for(int i=1;i<=k;i++){
if(num%2==0)
num=num/2;
if(num%5==0)
num=num/5;
temp=temp*10;
}
cout<<num*temp<<endl;
return 0;
}

本文介绍了一种名为K-Rounding的算法实现方案,该算法旨在找到一个最小的正整数x,使得x既能被给定的正整数n整除,又能以10为底包含至少k个0。通过两种不同的方法探讨了这一问题的解决方案,一种是遍历查找的方式,另一种则是利用最大公约数进行优化。
2880

被折叠的 条评论
为什么被折叠?



