Advertisement
Saleh127

Light oj(LO) 1090

Apr 10th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll fact(ll n,ll x)
  6. {
  7. ll c=0;
  8. while(n>0)
  9. {
  10. c+=(n/x);
  11. n/=x;
  12. }
  13. return c;
  14. }
  15. ll ppowerq(ll n,ll x)
  16. {
  17. ll c=0;
  18. while(n%x==0)
  19. {
  20. c++;
  21. n/=x;
  22. }
  23. return c;
  24. }
  25. int main()
  26. {
  27. ios_base::sync_with_stdio(0);
  28. cin.tie(0);cout.tie(0);
  29.  
  30.  
  31.  
  32. test
  33. {
  34. ll n,r,p,q,two,five,ans=0;
  35.  
  36.  
  37. cin>>n>>r>>p>>q;
  38.  
  39.  
  40. two=fact(n,2); ///how many 2 in nCr +n!,-(n-r)!,-r!
  41. two-=fact(n-r,2);
  42. two-=fact(r,2);
  43. two+=(ppowerq(p,2)*q); ///how many 2 in p^q;
  44.  
  45. five=fact(n,5); ///how many 5 in nCr +n!,-(n-r)!,-r!
  46. five-=fact(n-r,5);
  47. five-=fact(r,5);
  48. five+=(ppowerq(p,5)*q); ///how many 5 in p^q
  49.  
  50. ans=min(two,five);
  51.  
  52. cout<<"Case "<<cs<<": "<<ans<<endl;
  53. }
  54.  
  55. return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement