#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 1000006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; constint P = 998244353; int n , m , k; int A[MAXN];
intgcd( int a , int b ){ return !b ? a : gcd( b , a % b ); }
int pri[MAXN] , en , phi[MAXN]; voidsieve( ){ phi[1] = 1; rep( i , 2 , MAXN - 1 ) { if( !pri[i] ) pri[++ en] = i , phi[i] = i - 1; for( int j = 1 ; j <= en && pri[j] * i < MAXN ; ++ j ) { pri[i * pri[j]] = 1; if( i % pri[j] == 0 ) { phi[i * pri[j]] = phi[i] * pri[j]; break; } phi[i * pri[j]] = phi[i] * ( pri[j] - 1 ); } } }
int cs[4] , xs[4];
int J[MAXN] , iJ[MAXN];
intPow( int x , int a ){ int ret = 1; while( a ) { if( a & 1 ) ret = ret * 1ll * x % P; x = x * 1ll * x % P , a >>= 1; } return ret; }
intC( int a , int b ){ if( a < b || b < 0 ) return0; return J[a] * 1ll * iJ[b] % P * iJ[a - b] % P; }
intf( int a , int b ){ if( a == b ) return a < k ? 1 : 0; int res = 0; rep( o , 0 , 2 ) { int rem = b - cs[o] , x = xs[o]; rep( i , 0 , min( a - b - 1 , rem / k ) ) { int tx = C( a - b - 1 , i ) * 1ll * x % P; tx = ( i & 1 ) ? P - tx : tx; res = ( res + tx * 1ll * C( rem + a - b , a - b ) ) % P; rem -= k; } } return res; }
voidsolve(){ cin >> n >> m >> k; ++ k; cs[0] = 0 , cs[1] = k , cs[2] = k + 1; xs[0] = 1 , xs[1] = P - ( k + 1 ) , xs[2] = k; int g = gcd( n , m ) , res = 0; for( int i = 1 ; i * i <= g ; ++ i ) if( g % i == 0 ) { res = ( res + f( n / i , m / i ) * 1ll * phi[i] ) % P; if( i * i != g ) res = ( res + f( n / ( g / i ) , m / ( g / i ) ) * 1ll * phi[g / i] ) % P; } cout << res * 1ll * Pow( n , P - 2 ) % P << endl; }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 999 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; constint P = 1e9 + 7; int n , m; int A[MAXN];
intgcd( int a , int b ){ return !b ? a : gcd( b , a % b ); }
intPow( int x , int a ){ int ret = 1; while( a ) { if( a & 1 ) ret = ret * 1ll * x % P; x = x * 1ll * x % P , a >>= 1; } return ret; }
vi pr; voidwkr( int x , int lim ){ if( x == 0 ) { int w = J[n]; int las = 0 , cn = 0; for( int x : pr ) { w = w * 1ll * iv[x] % P; if( x != las ) w = w * 1ll * iJ[cn] % P , las = x , cn = 1; else ++ cn; } w = w * 1ll * iJ[cn] % P; mem( dp ); dp[0][1] = 1; rep( j , 1 , m ) { rep( i , 0 , m ) { int ic = 1; int p = 1; for( int x : pr ) p = p * 1ll * p2[gcd( x , j )] % P; rep( k , 0 , ( m - i ) / j ) { dp[i + j * k][j + 1] = ( dp[i + j * k][j + 1] + dp[i][j] * 1ll * iJ[k] % P * ic ) % P; ic = ic * 1ll * iv[j] % P * p % P; } } } // cout << dp[2][2] << endl; res = ( res + dp[m][m + 1] * 1ll * w ) % P; return; } rep( k , lim , x ) pr.pb( k ) , wkr( x - k , k ) , pr.pop_back(); }
voidsolve(){ J[0] = iJ[0] = p2[0] = 1; rep( i , 1 , MAXN - 1 ) J[i] = J[i - 1] * 1ll * i % P , iv[i] = Pow( i , P - 2 ) , iJ[i] = iJ[i - 1] * 1ll * iv[i] % P , p2[i] = p2[i - 1] * 2 % P; cin >> n >> m; if( n > m ) swap( n , m ); wkr( n , 1 ); cout << res * 1ll * iJ[n] % P << endl; }
#include"iostream" #include"algorithm" #include"cstring" #include"cstdio" #include"cmath" #include"vector" #include"map" #include"set" #include"queue" usingnamespace std; #define MAXN 999 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedeflonglong ll; constint P = 997; int n , m; int A[MAXN];
intgcd( int a , int b ){ return !b ? a : gcd( b , a % b ); }
intPow( int x , int a ){ int ret = 1; while( a ) { if( a & 1 ) ret = ret * 1ll * x % P; x = x * 1ll * x % P , a >>= 1; } return ret; }
int pn , as = 0 , iv[MAXN] , p2[MAXN] , J[MAXN]; vi pr; voidwkr( int x , int lim ){ if( x == 0 ) { int w = pn , tw = 0; int las = 0 , cn = 0; for( int x : pr ) { if( x != las ) w = w * iv[J[cn]] % P , las = x , cn = 1; else ++ cn; } w = w * iv[J[cn]] % P; for( int x : pr ) w = w * iv[x] % P , tw += x / 2; for( int i = 0 ; i < pr.size() ; ++ i ) for( int j = 0 ; j < i ; ++ j ) tw += gcd( pr[i] , pr[j] ); as = ( as + w * p2[tw % ( P - 1 )] ) % P; return; } rep( k , lim , x ) pr.pb( k ) , wkr( x - k , k ) , pr.pop_back(); }
voidsolve(){ cin >> n; p2[0] = J[0] = pn = 1; rep( i , 1 , n ) pn = pn * i % P; rep( i , 1 , P - 1 ) iv[i] = Pow( i , P - 2 ) , p2[i] = p2[i - 1] * 2 % P , J[i] = J[i - 1] * i % P; wkr( n , 1 ); cout << as * 1ll * iv[pn] % P << endl; }