Question:
For (I = A; I! = B; I + = C) the number of cycles in the K-bit operating system.
If yes, the number of cycles is output.
Otherwise, an endless loop is output.
In this case, I = 65533; I <= 2; I + = 4; I = 2;
From modulus linear equation-> Extended Euclidean
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <queue> using namespace STD; # define min int_min # define Max int_max # define n 204 # define ll _ int64ll int gcd (ll n, ll m) {ll R; while (M! = 0) {r = n % m; n = m; M = r;} return N;} void exgcd (ll a, LL B, ll & X1, ll & Y1) {If (B = 0) {x1 = 1; Y1 = 0; return;} exgcd (B, A % B, X1, Y1 ); // tossing and division ll T = x1; X1 = Y1; Y1 = T-A/B * Y1; // set N % B =; -> A = N-N/B; return;} int main () {ll a, B, c, K; while (~ Scanf ("% i64d % i64d % i64d % i64d", & A, & B, & C, & K) {// int sum = 0; if (A = 0 & B = 0 & C = 0 & K = 0) break;/* For (INT I = 1; I <= 7; I + = 2) {sum ++; cout <I <''<Endl ;} * // derivation process // the remainder is not considered. The number of times is (B-) /C + 1 // number of assumptions x = (B-A + 1 <k) % (1 <k)/C // Deformation: cx = (B-A + 1 <k) % (1 <k) // according to the White Book, the Model Linear Equation Cx = (B-) % (1 <k) // Therefore: (CX-(B-A) must be a multiple of (1 <K, set the multiples to y // deformation to the Extended Euclidean formula: Cx-(1 <k) y = (B-a) // hence: (B-a) % gcd (C, 1 <K) = 0 ll A, C, X1, Y1; LL B = (LL) 1 <K; A = C; C = B-A; ll ST = gcd (A, B ); // cout <st <Endl; If (C % st! = 0) puts ("forever"); else {exgcd (a, B, X1, Y1); X1 = x1 * (C/ST) % B; x1 = (x1% (B/ST) + B/ST) % (B/ST); // ll TT = (X1 + (C/ST )) % (C/ST); cout <X1 <Endl ;}} return 0 ;}