Advertisement
Farjana_akter

Untitled

Jun 2nd, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. ll t,i,cas,j,k,X,N,M,Y,a,b,c,d,e;
  10. cin>>t;
  11. for(cas=1;cas<=t;cas++)
  12. {
  13. cin>>X>>N>>Y>>M;
  14. a=X;
  15. b=0;
  16. if(N==0)
  17. a+=Y;
  18. for(i=1;i<=N;i++)
  19. {
  20. if(a<b)
  21. swap(a,b);
  22. b+=a;
  23. if(i==N)
  24. {
  25. if(a<b)
  26. swap(a,b);
  27. a+=Y;
  28. }
  29. }
  30. cout<<"Case "<<cas<<": "<<__gcd(a,b)<<endl;
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement