Advertisement
Saleh127

UVA 350

Oct 12th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 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. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. ll z,i,m,l,j,k,c,d,e=0;
  11. while(cin>>z>>i>>m>>l && z && i && m && l)
  12. {
  13. ll a[100005]={0};
  14. c=0;
  15. l=(z*l+i)%m;
  16. while(a[l]==0)
  17. {
  18. c++;
  19. a[l]=1;
  20. l=(z*l+i)%m;
  21. }
  22. cout<<"Case "<<++e<<": "<<c<<endl;
  23. }
  24.  
  25.  
  26. return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement