Advertisement
Emiliatan

d791

Aug 12th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. /* d791           */
  2. /* AC (2ms, 72KB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <tuple>
  10. #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  11.  
  12. using namespace std;
  13.  
  14. using int16 = short;
  15. using uint16 = unsigned short;
  16. using uint = unsigned int;
  17. using int64 = long long;
  18. using uint64 = unsigned long long;
  19. using pii = pair<int, int>;
  20.  
  21. /* exgcd  __X * a + __Y * b = gcd(a, b) */
  22. int64 __X, __Y;
  23. tuple<int64, int64, int64> exgcd(int64 a, int64 b) noexcept
  24. {
  25.     if (b == 0)
  26.     {
  27.         __X = 1;
  28.         __Y = 0;
  29.         return { __X, __Y, a };
  30.     }
  31.     int64 r = get<2>(exgcd(b, a % b));
  32.     int64 tmp = __X;
  33.     __X = __Y;
  34.     __Y = tmp - a / b * __Y;
  35.     return { __X, __Y, r };
  36. }
  37.  
  38. /* main code */
  39. constexpr int M = 23 * 28 * 33;
  40. int abW = get<0>(exgcd(23 * 28, 33));
  41. int acW = get<0>(exgcd(23 * 33, 28));
  42. int bcW = get<0>(exgcd(28 * 33, 23));
  43. int p, e, i, d, x, t = 1;
  44.  
  45. int main()
  46. {
  47.     abW = (abW % 33 + 33) % 33;
  48.     acW = (acW % 28 + 28) % 28;
  49.     bcW = (bcW % 23 + 23) % 23;
  50.  
  51.     while (~scanf("%d %d %d %d", &p, &e, &i, &d) && p >= 0)
  52.     {
  53.         x = (p * (28 * 33) * bcW + e * (23 * 33) * acW + i * (23 * 28) * abW - d) % M;
  54.         while (x <= 0) x += M;
  55.  
  56.         printf("Case %d: the next triple peak occurs in %d days.\n", t++, x);
  57.     }
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement