Description has only two sentences
Time Limit: 3000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 886 accepted submission (s): 265
Problem descriptionan = x * an-1 + Y and y MOD (X-1) = 0.
Your task is to calculate the smallest positive integer k that AK mod a0 = 0.
Inputeach line will contain only three integers x, y, a0 (1 <x <231, 0 <= Y <263, 0 <A0 <231 ).
Outputfor each case, output the answer in one line, if there is no such K, output "impossible! ".
Sample input2 0 9
Sample output1
Authorwhereisherofrom
Sourcehdoj monthly contest-2010.02.06
Ask for a minimum K of AI = Xai + Y and Y % (x-1) = 0 AK % A0 = 0
Then start to push the formula
A n = x ^ N * A0 + (x ^ (n-1) + x * (n-2) +... + x + 1) * y
Obviously, x ^ N * a0 must be divisible by A0, which can be ignored, and then the following item is an proportional sequence.
Then, the minimum k (x ^ k-1)/(x-1) * Y % A0 = 0 is obtained.
.. Set the coefficient to E,
E * a0 = (x ^ k-1)/(x-1) * Y;
E * (A0/gcd (A0, Y/(x-1) = x ^ k-1.
Set M = (A0/gcd (A0, Y/(x-1 ))).
Obtain x ^ K = 1 (mod m)
Evaluate a single Euler for M and judge it.
Impossible should determine whether X and m are mutually qualitative. If not, x ^ K % m must be a multiple of gcd (M, X ).
#include <algorithm>#include <cstring>#include <cstdio>#include <queue>#include <iostream>#include <vector>#include <string>#include <map>using namespace std;typedef long long ll;const int N = 100010;ll mod , tot ;ll gcd ( ll a , ll b ) { return b == 0 ? a : gcd( b ,a % b ); }ll eular ( ll n ){ ll sum = n ; for( ll i = 2 ; i* i <= n ; ++i ){ if( n % i == 0 ){ sum = sum / i *( i -1 ); while( n % i == 0 ) n /= i ; } } if( n > 1 ) sum = sum / n * ( n -1 ) ; return sum;}ll quick_mod( ll a , ll b ){ ll res = 1 ; while( b ){ if( b & 1 ) res = res * a % mod ; a = a * a % mod; b >>= 1 ; } return res ;}ll e[N] ;void get_factor( ll n ){ for( ll i = 2 ; i * i <= n ; ++i ){ if( n % i == 0 ){ e[tot++] = i ; if( n / i != i ) e[tot++ ] = n / i ; } }}int main(){ ios::sync_with_stdio(0); #ifdef LOCAL freopen("in.txt","r",stdin); #endif ll a0 , x , y ; while( cin >> x >> y >> a0 ){ tot = 0 ; if( !y ) { cout << ‘1‘ <<endl ; continue ;} ll m = a0 / gcd( y / ( x - 1 ) ,a0 ) ; if( gcd(m ,x) != 1 ) { cout << "Impossible!" << endl ; continue ; } ll phi = eular(m) ; get_factor(phi) ; sort(e , e + tot ) ; mod = m ; for( int i = 0 ; i < tot ; ++i ){ if( quick_mod( x,e[i]) == 1 ){ cout <<e[i] << endl ; break ; } } }}
HDU 3307 description has only two sentences