传送门:点击打开链接
A. k-rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
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
找到前一个数的倍数,满足后缀有K个0,输出最小的那个数。刚开始是暴力,一一枚举n的倍数,后来发现第四组示例跑死了啊,4秒才出结果,12345678900000000实在是太大了,只好换别的方法,又想到单独处理质数,然后合数求GCD试试,后来发现为什么要单独判断质数呢?直接全部GCD就OK了。
代码实现:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=100005;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int main()
{
ll n,k,i,flag;
while(cin>>n>>k)
{
ll temp=fpow(10ll,k);
ll ans=gcd(n,temp);
cout<<temp/ans*n<<endl;
}
return 0;
}