LightOJ - 1090 - Trailing Zeroes(II)
Problem Link: http://lightoj.com/volume_showproblem.php?problem=1090
Code:
#include <bits/stdc++.h>
using namespace std;
int fact(int n, int k)
{
//int f=n;
int coun=0;
while(n>=k)
{
coun+=n/k;
n/=k;
}
return coun;
}
int poww(int n, int k)
{
int coun=0;
if(n%k==0)
{
while(n%k==0)
{
n/=k;
coun++;
}
}
return coun;
}
int main()
{
int t,f=0;
cin>>t;
while(t--)
{
f++;
int n,r,p,q;
cin>>n>>r>>p>>q;
int a1,a2,b1,b2,c1,c2;
a1=fact(n,2);
// cout<<"---"<<a1<<endl;
a2=fact(n,5);
// cout<<"---"<<a2<<endl;
b1=fact(r,2);
// cout<<"---"<<b1<<endl;
b2=fact(r,5);
// cout<<"---"<<b2<<endl;
b1+=fact(n-r,2);
b2+=fact(n-r,5);
a1-=b1;
a2-=b2;
//a1=min(a1,a2);
c1=poww(p,2);
c1*=q;
c2=poww(p,5);
c2*=q;
a1+=c1;
a2+=c2;
a1=min(a1,a2);
cout<<"Case "<<f<<": "<<a1<<endl;
}
return 0;
}
No comments:
Post a Comment