#include
#include
#include
using namespace std;
int16_t zetas_base[384] = {
2722, 1708, 2484, 973, 735, 1749, 686, 941, 1830, 1627, 2771, 2516, 63, 545, 2849, 608,
3394, 2912, 1324, 1796, 337, 3120, 2133, 1661, 2970, 1000, 2944, 513, 487, 2457, 685, 219,
2553, 904, 2772, 3238, 1227, 902, 1328, 2129, 2230, 2555, 929, 80, 2448, 1009, 2528, 3377,
418, 1037, 2002, 1455, 3039, 2420, 2145, 3411, 1358, 2099, 1312, 46, 2631, 1689, 2594, 863,
826, 1768, 310, 2572, 575, 2882, 3147, 885, 2544, 1101, 3269, 188, 913, 2356, 1774, 1738,
3402, 55, 1683, 1719, 2350, 2770, 1794, 1663, 1107, 687, 2416, 2024, 2474, 983, 1041, 1433,
3236, 2917, 761, 2696, 221, 540, 2050, 504, 903, 2554, 1407, 2953, 2587, 1034, 3293, 164,
870, 2423, 812, 2031, 614, 2843, 2645, 1426, 2939, 2817, 1158, 2299, 518, 640, 253, 2902,
302, 3155, 3204, 555, 2810, 3018, 1086, 2371, 647, 439, 3139, 2023, 1752, 1705, 318, 1434,
977, 166, 2314, 1143, 2480, 3291, 10, 306, 3141, 316, 3447, 3151, 2188, 3344, 1382, 2075,
1269, 113, 493, 3332, 3089, 368, 2964, 125, 1414, 1093, 950, 2507, 2043, 2364, 524, 1515,
1418, 2039, 2933, 1942, 1953, 3067, 1894, 1563, 1504, 390, 3017, 364, 76, 3381, 440, 3093,
406, 2744, 307, 3150, 3051, 713, 82, 435, 2940, 517, 3375, 3022, 1348, 1839, 270, 3187,
2109, 1618, 1277, 2432, 3205, 252, 2180, 1025, 3298, 2740, 876, 2581, 159, 717, 2914, 2052,
1948, 1509, 543, 1405, 2878, 259, 320, 3137, 579, 3198, 3306, 1602, 2006, 1451, 151, 1855,
1975, 1666, 3273, 184, 1482, 1791, 2766, 2363, 1785, 1672, 691, 1094, 2300, 1240, 3374, 83,
1157, 2217, 158, 3452, 3304, 153, 3299, 5, 3237, 182, 38, 3419, 220, 3275, 2510, 752,
195, 3262, 947, 2705, 2982, 2750, 1182, 2275, 475, 707, 2748, 3195, 971, 2486, 709, 262,
155, 1286, 2016, 1441, 3302, 2171, 2160, 413, 884, 2573, 1297, 3044, 2456, 3248, 1210, 2247,
1001, 209, 2778, 656, 23, 3434, 679, 2801, 1208, 1012, 1237, 2220, 2249, 2445, 2560, 2282,
2072, 1385, 897, 1175, 94, 2185, 1178, 2279, 3363, 1272, 1756, 2570, 2588, 869, 1701, 887,
2193, 40, 1224, 2233, 1264, 3417, 2793, 1115, 3006, 451, 664, 2342, 1985, 1972, 2957, 500,
1472, 1485, 452, 1386, 1619, 1838, 3005, 2071, 2215, 2096, 2603, 854, 1242, 1361, 2542, 3114,
1258, 2199, 915, 343, 304, 1697, 1456, 2001, 3153, 1760, 1560, 2795, 2559, 898, 1897, 662 };
int qmi(int a, int n, int q) {
int ans = 1;
while (n) {
if (n & 1)ans = ans * a % q;
a = a * a % q;
n >>= 1;
}
return ans;
}
int calc(int v) {
for (int i = 0; i <= 1152; i++) {
if (qmi(5, i, 3457)*3310%3457 == v)return i;
}
return -1;
}
int seq[384];
int ans[384];
pair<int, int> exgcd(int a, int b) {
int r0 = a, y0 = 1, u0 = 0;
int r1 = b, y1 = 0, u1 = 1;
int r2, y2, u2;
while (r1 = a * y1 + b * u1) {
auto q = r0 / r1;
y2 = y0 - q * y1, u2 = u0 - q * u1;
y0 = y1, u0 = u1, r0 = r1;
y1 = y2, u1 = u2;
}
return { y0,u0 };
}
int test() {
for (int i = 0; i < 384; i++) {
seq[i]=calc(zetas_base[i]);
if (seq[i] == -1)std::cout << "error" <<std::endl;
}
for (int i = 0; i < 384; i++) {
ans[i] = qmi(38, seq[i], 10369);
}
for (int i = 0; i < 384; i++) {
if (i % 16 == 0)puts("");
std::cout << ans[i] << ",";
}
return 0;
}
pair<long long , long long> get(int a, int b) {
auto t= exgcd(a, b);
int aa = t.first, bb = t.second;
if (b * bb + a * aa != 1)cout << "error" << endl;
long long t1 = (long long)b * bb % (a * b), t2 =(long long) a * aa % (a * b);
if (t1 < 0)t1 += a * b;
if (t2 < 0)t2 += a * b;
return { t1,t2 };
}
int calc(int a, int b) {
long long ta = 17917632, tb = 17928002;
int t = (a * ta + b * tb) % (3457 * 10369ll);
if (t < 0)t += (3457 * 10369ll);
return t;
}
int check(long long val) {
long long a = val % 3457;
long long b = val % 10369;
return calc(a, b);
}
long long barret(int x,int n) {
long long k = 1;
while ((1ll << k) < n)k++;
long long k_4 = (1ll << (2 * k));
long long r = k_4 / n;
long long t = x - x * r / k_4 * n;
if (t >= n)return t - n;
return t;
}
int main() {
auto t = get(3457, 10369);
long long maxv = 0;
for (int i = 0; i < 3457 * 3457; i++) {
maxv = max(maxv, barret(i,3457));
}
cout << maxv << endl;
}