Mathematics is hard.
After analyzing the question, we know that sigma (C [I, n] % mod)
1 bytes ≤ bytesNLimit ≤ limit 106
There are two methods below,
1. pre-process the factorial, directly according to the combination number formula C [I, n] = n! /(I! * (N-I )! ), Because Division modulo is involved, the reverse element is required.
62 Ms.
# Include <cstdio> # include <cstring> # include <iostream> # include <cmath> # include <string> # include <vector> # include <map> # include <algorithm> using namespace STD; inline int RINT () {int X; scanf ("% d", & X); Return X;} inline int max (int x, int y) {return (x> Y )? X: Y;} inline int min (int x, int y) {return (x <Y )? X: Y ;}# define for (I, a, B) for (INT I = (a); I <= (B); I ++) # define Ford (I, a, B) for (INT I = (a); I >= (B); I --) # define rep (X) for (INT I = 0; I <(x); I ++) typedef long int64; # define Inf (1 <30) const double EPS = 1e-8; # define bug (s) cout <# S <"=" <S <"/a, B, N // 1 limit ≤ limit a limit <limit B Limit ≤ limit 9, limit 1 limit ≤ limit n Limit ≤ limit 10 ^ 6 # define maxn 1000000 # define mod limit 7int, b; int64 fact [maxn + 2]; int isgood (INT X) {for (; X/= 10) {If (X % 10! = A & X % 10! = B) {return 0 ;}} return 1 ;}void calc_fact () {fact [0] = 1; for (I, 1, maxn) {fact [I] = fact [I-1] * I % MOD;} void ext_gcd (int64 A, int64 B, int64 & D, int64 & X, int64 & Y) {If (! B) {d = A; X = 1; y = 0;} else {ext_gcd (B, A % B, D, Y, X ); y-= x * (a/B);} int64 inv_mod (int64 A) // IX = 1 (mod n) {int64 X, Y, D; ext_gcd (, moD, D, x, y); While (x <0) {x + = MOD;} return X;} int64 C (int K, int N) {return fact [N] * inv_mod (fact [k] * fact [n-k]) % MOD;} int main () {A = RINT (); B = RINT (); int n = RINT (); calc_fact (); int64 ans = 0; for (I, 0, n) {If (isgood (A * I + B * (N-I) {ans = (ANS + C (I, n) % mod ;}} printf ("% LLD \ n", ANS );}
2. According to the recursive formula C [I] = C [I-1] * (N-I + 1)/I, first introduce all C [N, I], this is because n won't change. We also need to find the reverse element for I.
531 Ms
# Include <cstdio> # include <cstring> # include <iostream> # include <cmath> # include <string> # include <vector> # include <map> # include <algorithm> using namespace STD; inline int RINT () {int X; scanf ("% d", & X); Return X;} inline int max (int x, int y) {return (x> Y )? X: Y;} inline int min (int x, int y) {return (x <Y )? X: Y ;}# define for (I, a, B) for (INT I = (a); I <= (B); I ++) # define Ford (I, a, B) for (INT I = (a); I >= (B); I --) # define rep (X) for (INT I = 0; I <(x); I ++) typedef long int64; # define Inf (1 <30) const double EPS = 1e-8; # define bug (s) cout <# S <"=" <S <"/a, B, N // 1 limit ≤ limit a limit <limit B Limit ≤ limit 9, limit 1 limit ≤ limit n Limit ≤ limit 10 ^ 6 # define maxn 1000000 # define mod limit 7int, b; int isgood (INT X) {for (; X/= 10) {If (X % 10! = A & X % 10! = B) {return 0 ;}} return 1 ;}void ext_gcd (int64 A, int64 B, int64 & D, int64 & X, int64 & Y) {If (! B) {d = A; X = 1; y = 0;} else {ext_gcd (B, A % B, D, Y, X ); y-= x * (a/B);} int64 inv_mod (int64 A) // IX = 1 (mod n) {int64 X, Y, D; ext_gcd (, moD, D, x, y); While (x <0) {x + = MOD;} return X;} // int64 C (int K, int N) {// return fact [N] * inv_mod (fact [k] * fact [n-k]) % MOD; ///} // # define maxn 0000002int64 C [maxn + 2]; int64 C (int64 N, int64 K) // C n k {C [0] = 1; for (int64 I = 1; I <= K; I ++) {C [I] = C [I-1] * (N-I + 1) % mod * inv_mod (I) % MOD;} return C [k];} int main () {A = RINT (); B = RINT (); int n = RINT (); // calc_fact (); C (n, n); int64 ans = 0; for (I, 0, n) {If (isgood (A * I + B * (N-I) {ans = (ANS + C [I]) % mod ;}} printf ("% LLD \ n", ANS );}
In addition, I feel that I want to reverse the yuanCodeIs it a setback? It seems that I used to write a combination of mathematical questions for a longer time than others ..
Mathematical reasoning cannot be remembered now .. There is nothing .. T-T