#include<iostream>
using namespace std;
const int N = 100000;
const int mol = 20090531;
int a[N], p[N/10];
int p_fac[10], p_cnt[10], p_k;
int pf1[10], pc1[10], pk1;
int ans, m, n;
int prime2( int n)
{
int i, j, k, t;
for ( i = 2 , k = 0 ; i < n ; i ++ )
{
if( !a[i] )
p[ k ++ ] = a[i] = i;
for ( j = 0 ; j < k ; j ++ )
{
t = p[j] * i;
if ( t >= n )
break;
a[ t ] = p[ j ];
if( i % p[j] == 0 )
break;
}
}
return k;
}
// 要求 n > 1
void fac_break( int n )
{
if( n < N ){
int t ;
p_k = p_cnt[ 0 ] = 0;
while( n != 1 )
{
t = p_fac[ p_k ] = a[n];
while( n % t == 0 )
{
n /= t , p_cnt[ p_k ] ++ ;
}
p_k ++;
p_cnt[ p_k ] = 0;
}
}
else
{
p_k = p_cnt [ 0 ] = 0;
for ( int i = 2 ; i * i <= n ; i ++ )
{
if( n % i == 0 )
{
p_fac[ p_k ] = i;
while ( n % i == 0 )
{
p_cnt [ p_k ] ++;
n /= i;
}
p_k ++;
p_cnt[ p_k ] = 0;
}
}
if( n != 1 ){
p_fac[ p_k ] = n;
p_cnt[ p_k ++ ] = 1;
}
}
}
int ruler( int n)
{
fac_break( n );
for ( int i = 0 ; i < p_k ; i ++ ){
n /= p_fac[ i ];
n *= p_fac[ i ] - 1;
}
return n;
}
int mol_pow( int a, int b )
{
int t = a, ans = 1;
while( b ){
if( b & 1 ){
ans = 1ll * ans * t % mol;
}
t = 1ll * t * t % mol;
b >>= 1;
}
return ans;
}
// 生成所有约数。 已经调用了 fac_break();
void make_div( int k, int val ){
if( k == p_k ){
int t = ruler( n / val );
ans = ( 1ll * t * mol_pow( m, val ) % mol + ans ) % mol;
return ;
}
int t = 1;
for ( int i = 0 ; i <= p_cnt[ k ] ; i ++ )
{
make_div( k + 1, val * t , p_fac, p_cnt, p_k, n, m );
t *= p_fac[ k ];
}
}
int ext_gcd( int a,int b,int &x,int &y)
{
if( b == 0 )
{
x = 1, y = 0;
return a;
}
else
{
int d = ext_gcd( b, a%b, x, y );
int t = x;
x = y;
y = t - a/b*y;
return d;
}
}
int ni( int n )
{
int x, y;
ext_gcd( n, mol, x, y );
x %= mol;
if( x < 0 )
x += mol;
return x;
}
posted on 2009-08-19 15:36
Huicpc217 阅读(152)
评论(0) 编辑 收藏 引用 所属分类:
模板