Hdu 3304 Interesting Yang Yui Triangle
Hdu 3304 Interesting Yang Yui Triangle
Question:
If P, N is given, how many Fibonacci numbers P in the nth line are not equal to 0?
Restrictions:
P <1000, N <= 10 ^ 9
Ideas:
Lucas theorem,
If:
N = a [k] * p ^ k + a [k-1] * p ^ (k-1) +... + a [1] * p + a [0]
M = B [k] * p ^ k + B [k-1] * p ^ (k-1) +... + B [1] * p + B [0]
Then:
C (n, m) = pe (I = 0 ~ K, C (a [I], B [I]) % p in which pe represents the Concatenation symbol.
Since n has been determined, a [I] (0 <= I <= k) has been determined, so we only need to find out how many types of B [I] each a [I] has, make C (a [I], B [I]) % P! = 0. The brute force attack is enough.
/* Hdu 3304 Interesting Yang Yui Triangle? Restriction: P <1000, N <= 10 ^ 9 train of thought: lucas theorem, if: n = a [k] * p ^ k + a [k-1] * p ^ (k-1) +... + a [1] * p + a [0] m = B [k] * p ^ k + B [k-1] * p ^ (k-1) +... + B [1] * p + B [0]: C (n, m) = pe (I = 0 ~ K, C (a [I], B [I]) % p in which pe represents the Concatenation symbol. Since n has been determined, a [I] (0 <= I <= k) has been determined, so we only need to find out how many types of B [I] each a [I] has, make C (a [I], B [I]) % P! = 0. The brute force attack is enough. */# Include
# Include
Using namespace std; # define LL long longconst int MOD = 10000; const int N = 105; int a [N]; int cnt = 0; int ny [N]; LL inv (LL a, LL m) {LL p = 1, q = 0, B = m, c, d; while (B> 0) {c = a/B; d = a; a = B; B = d % B; d = p; p = q; q = d-c * q;} return p <0? P + m: p;} void predo (int p) {ny [0] = 1; for (int I = 1; I