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 10and 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.
The only line contains two integers n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ 8).
Print the k-rounding of n.
375 4
30000
10000 1
10000
38101 0
38101
123456789 8
12345678900000000
暴力鸟进球!就很开心
差点写不出A题QAQ
以后看到整除就要往质因数上想
题意就是(x*10^k)%n==0求最小的x
所以(x*10^k)里面至少要有n的所有质因子的t次方
我们gcd(10^k,n)求出10^k和n里面共有的质因子
再用n/gcd,就可以得到x(gcd里面没有的质因子或者t不够的在x里面补上)
最后输出(x*10^k)
——————————————————分割线————————————————————————
后来才发现其实就是求lcm(10^k,n)QAQ
#include<cstdio>
#include<cstring>
int read()
{
int ans=0;char t=getchar();
while(t<'0'||t>'9') t=getchar();
while(t>='0'&&t<='9') ans=ans*10+t-'0',t=getchar();
return ans;
}
int gcd(int a,int b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
int n=read(),k=read();
int tt=1;
for(int i=1;i<=k;i++) tt*=10;
int kk=gcd(n,tt);
printf("%I64d\n",(long long)tt*(n/kk));
return 0;
}