Saturday, October 19, 2019

CodeForces -  k-rounding



Idea: 

Code First Then See Solution

Code: 
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll n,sum=1;
    int k;
    cin>>n>>k;
    int cnt2=0,cnt5=0;
    ll f=n;
    while(f%2==0)
    {
        cnt2++;
        f/=2;
    }
    f=n;
     while(f%5==0)
    {
        cnt5++;
        f/=5;
    }
    cnt2=max(k-cnt2,0);
    cnt5=max(k-cnt5,0);
    for(ll i=0;i<cnt2;i++)
        sum*=2;
    for(ll i=0;i<cnt5;i++)
        sum*=5;
    cout<<sum*n<<endl;
    return 0;

}

No comments:

Post a Comment