Codeforces 434 Div. 2 A

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

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;   

}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值