Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用这个方法过了 不过用逆元怎么都过不了 与AC的程序测了无数组数据 都没错啊 附上代码 忘大牛们指点

Posted by alpc56 at 2009-09-10 18:01:43 on Problem 1845
In Reply To:计算((p^(eB+1)-1)/(p-1))%MOD Posted by:dirtysalt at 2009-09-04 15:32:53
#include <stdio.h>

#define ll __int64
#define mod 9901

ll expmod(ll a,ll b)		// a^b(mod 9901)
{
	if( b==0 )
		return 1;
	ll k = expmod(a,b/2);
	if( b&1 )
		return (k*k*a)%mod;
	else
		return (k*k)%mod;
}

ll gcd(ll e,ll f)		// e关于f逆元
{
    ll x1,x2,x3,y1,y2,y3;
    ll t1,t2,t3;
    x1 = 1,x2 = 0,x3 = f;
    y1 = 0,y2 = 1,y3 = e;
    while( 1 )
    {
        if( y3==0 )
            return -1;
        if( y3==1 )
            return y2;
        ll k = x3/y3;
        t1 = x1-k*y1;t2 = x2-k*y2;t3 = x3-k*y3;
        x1 = y1,x2 = y2,x3 = y3;
        y1 = t1,y2 = t2,y3 = t3;
    }
}

ll getA(ll p,ll a,ll b) // (p^(a*b+1)-1)/(p-1)%9901
{
	ll k = expmod(p%mod,a*b+1);
	k = (k-1+mod)%mod;
	ll x = gcd(p-1,mod);
	if( x<0 )
		x += mod;
	k *= x;
	return k%mod;
}

main()
{
	ll a,b;
	while( scanf("%I64d%I64d",&a,&b)!=EOF )
	{
		ll as = 1;
		for(ll i=2;i*i<=a;i++)
		{
			ll k = 0;
			while( a%i==0 )
				k++,a /= i;
			if( k!=0 )
				as *= getA(i,k,b),as %= mod;
		}
		if( a==0 && b!=0 )
			printf("0\n");
		else
		{
			if( a!=1 )
				as *= getA(a,1,b);
			as %= mod;
			printf("%I64d\n",as);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator