- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- int find_p(int a, int b){
- int cn = 0;
- while(a > 0){
- cn += (a/b);
- a /= b;
- }
- return cn;
- }
- int find_pr(int a, int b){
- int cn = 0;
- while(!(a%b)){
- cn++;
- a /= b;
- }
- return cn;
- }
- int main(){
- int t, n, r, p, q, c, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d %d %d", &n, &r, &p, &q);
- c = n-r;
- int five_up = 0, five_down = 0, two_up = 0, two_down = 0;
- five_up = find_p(n, 5);
- two_up = find_p(n, 2);
- five_down = find_p(c, 5);
- five_down += find_p(r, 5);
- two_down = find_p(c, 2);
- two_down += find_p(r, 2);
- five_up += (q*find_pr(p, 5));
- two_up += (q*find_pr(p, 2));
- int five, two;
- five = five_up-five_down;
- two = two_up-two_down;
- int ans = min(five, two);
- printf("Case %d: %d\n", ++cs, ans);
- }
- return 0;
- }
Friday, March 11, 2016
LightOJ - 1090 - Trailing Zeroes (II)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment