#include char buf[2000000]; int main(void) { char *p = buf; int n = 0, m = 0, i; unsigned int f1 = 0, f2 = 1, fb = 0; fread(buf, sizeof(char), 2000000, stdin); if (*p < '1' || '9' < *p) { perror("invalid n"); return 1; } while ('0' <= *p && *p <= '9') { n = 10 * n + (int)(*p - '0'); p++; } if (*p != ' ') { perror("invalid separator"); return 1; } p++; if (*p < '1' || '9' < *p) { perror("invalid m"); return 1; } while ('0' <= *p && *p <= '9') { m = 10 * m + (int)(*p - '0'); p++; } if (*p != '\n') { perror("invalid newline"); return 1; } *p++; if (*p != '\0') { perror("invalid input"); return 1; } for (i = 3; i <= n; i++) { fb = (f1 + f2) % m; f1 = f2; f2 = fb; } printf("%u\n", fb); return 0; }