Advertisement
Emiliatan

c085

Apr 13th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /* c085            */
  2. /* AC (5ms, 672KB) */
  3. #include <cstdio>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. int Z, I, M, L, T = 1, Count;
  9. map<int, int> num;
  10.  
  11. int main()
  12. {
  13.     while(~scanf("%d %d %d %d", &Z, &I, &M, &L) && M)
  14.     {
  15.         Count = 1;
  16.         num.clear();
  17.         num.emplace(L, Count++);
  18.  
  19.         while(true)
  20.         {
  21.             L = (Z * L + I) % M;
  22.  
  23.             if(num.find(L) != num.end())
  24.                 break;
  25.  
  26.             num.emplace(L, Count++);
  27.         }
  28.  
  29.         auto it = num.find(L);
  30.  
  31.         printf("Case %d: %d\n", T++, Count - (it -> second));
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement