Advertisement
Saleh127

UVA Live Archive 6988/ Codechef Gabba sprint

Jul 26th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12.  
  13. ll n,m,i,j,k,l=0,p,q,s;
  14.  
  15. cin>>n>>m>>s>>p>>q;
  16.  
  17. ll a[s+2],b[s+2];
  18.  
  19. a[0]=b[0]=1;
  20.  
  21. for(i=1;i<=s;i++)
  22. {
  23. a[i]=a[i-1]+p;
  24. b[i]=b[i-1]+q;
  25.  
  26. while(a[i]>n)
  27. {
  28. a[i]=a[i]-n+m-1;
  29. ///cut the cycle of (n-m+1);
  30. }
  31.  
  32. while(b[i]>n)
  33. {
  34. b[i]=b[i]-n+m-1;
  35. ///cut the cycle of (n-m+1);
  36. }
  37.  
  38. if(a[i]==b[i]) l++;
  39. }
  40.  
  41.  
  42. cout<<l<<endl;
  43. }
  44.  
  45.  
  46. return 0;
  47. }
  48.  
  49.  
  50.  
  51. /*
  52.  
  53.  
  54. #include <bits/stdc++.h>
  55. using namespace std;
  56. #define ll long long
  57. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  58.  
  59. ll sol(ll n,ll m,ll x,ll y)
  60. {
  61. x+=y;
  62.  
  63. if(x<=m) return x;
  64.  
  65. x-=m;
  66.  
  67. return m+(x%(n-m+1));
  68. }
  69.  
  70.  
  71. int main()
  72. {
  73. ios_base::sync_with_stdio(0);
  74. cin.tie(0);
  75. cout.tie(0);
  76.  
  77.  
  78. test
  79. {
  80.  
  81. ll n,m,i,j,k,l=0,p,q,s;
  82.  
  83. cin>>n>>m>>s>>p>>q;
  84. j=1,k=1;
  85.  
  86. for(i=1; i<=s; i++)
  87. {
  88. j=sol(n,m,j,p);
  89. k=sol(n,m,k,q);
  90.  
  91. if(j==k) l++;
  92. }
  93. cout<<l<<endl;
  94. }
  95.  
  96.  
  97.  
  98. // new_pillarPosition = M +(current_pillarPosition + speed - M) % (N-M+1)
  99. // To reach to this formula,
  100. // we have to observe that
  101. // there is a cycle of length (N-M+1),
  102. // but a extra M is present in the pillar position,
  103. // which we can remove,
  104. // then add the speed and find the new position
  105. // in the cycle by taking a MOD with cycle length,
  106. // then add M again, to get the actual pillar number.
  107.  
  108. return 0;
  109. }
  110. */
  111.  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement