1090 – Trailing Zeroes (II)

http://lightoj.com/volume_showproblem.php?problem=1090

#Solution

#include <iostream>
#include<cstdio>
using namespace std;

int co_two_five_frc(int n,int dv)
{int q=dv;
int co=0;

while(n)
{
co+=n/dv;
n/=dv;
}
return co;

}
int co_two_five_p(int n,int dv)
{int q=dv;
int co=0;
while(n%dv==0)
{
co++;
n/=dv;

}
return co;

}

int main() {
int n,r,p,q,t,i=1;
scanf(“%d”,&t);
while(t–)
{scanf(“%d %d %d %d”,&n,&r,&p,&q);
int co2=q*co_two_five_p(p,2);
int co5=q*co_two_five_p(p,5);

int two;
two=co_two_five_frc(n,2)+co2;
two-=co_two_five_frc(r,2)+co_two_five_frc(n-r,2);
int fv=co_two_five_frc(n,5)+co5;
fv-=co_two_five_frc(r,5)+co_two_five_frc(n-r,5);
int ans=min(fv,two);

printf(“Case %d: %d\n”,i++,ans);

}
return 0;
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in lightoj, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s