unlucky_13

LOJ_1090 - Trailing Zeroes (II)

Jul 24th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. /*
  2. @author -> unlucky_13
  3. problem link::
  4. */
  5.  
  6. #include <iostream>
  7. #include<cstdio>
  8. #include<cstdlib>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<algorithm>
  12. #include<vector>
  13. #include<queue>
  14. #include<stack>
  15. #include<deque>
  16. #include<set>
  17. #include<list>
  18. #include<sstream>
  19. #include<fstream>
  20. using namespace std;
  21.  
  22. int catchPfac (int n,int p){
  23.     int cnt = 0 ;
  24.     while(n!=0){
  25.         cnt +=n/p ;
  26.         n =n/p ;
  27.     }
  28.  
  29.     return cnt ;
  30. }
  31. int catchPnum (int n,int P){
  32.     int cnt = 0 ;
  33.     while(n%P==0){
  34.         cnt ++ ;
  35.         n =n/P ;
  36.     }
  37.  
  38.     return cnt ;
  39. }
  40.  
  41. int main() {
  42.     //freopen("C:\\Users\\Mazhar\\Desktop\\eclipse\\in.txt","r",stdin) ;
  43.  
  44.     int tc,ct = 1,n, r, p,q;
  45.     scanf("%d",&tc) ;
  46.     while(tc--){
  47.         scanf("%d %d %d %d",&n,&r,&p,&q) ;
  48.         int t5 = catchPfac(n,5)-catchPfac(n-r,5)-catchPfac(r,5)+q*catchPnum(p,5) ;
  49.         int t2 = catchPfac(n,2)-catchPfac(n-r,2)-catchPfac(r,2)+q*catchPnum(p,2) ;
  50.         cout<<"Case "<<ct++<<": "<<min(t5,t2)<<endl ;
  51.  
  52.     }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment