Poj 2115 (modulus linear equation-> Extended Euclidean)

Source: Internet
Author: User


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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.