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

老兄,你这个有点问题,我给你改了一下

Posted by macslaytion at 2019-03-28 15:59:28 on Problem 3243
In Reply To:终于过了,有几点要说的 Posted by:jiyanmoyu at 2010-02-25 13:41:29
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
LL read(){
	LL x,f=1;char c;
	while((c=getchar())<'0'||'9'<c)
		if(c=='-')f=-1; 
	for(x=(c^48);'0'<=(c=getchar())&&c<='9';x=(x<<3)+(x<<1)+(c^48));
	return x*f;
}
const LL MAXN=1e5+5;
LL gcd(LL a,LL b){
	return b?gcd(b,a%b):a;
}
struct node{
	LL i,r;
	node(){
	}
	node(LL I,LL R):i(I),r(R){
	}
	friend bool operator < (const node& a,const node& b){
		if(a.r==b.r)return a.i<b.i;
		return a.r<b.r;
	}
}lis[MAXN];
bool cmpNode_for_lower_bound(const node& a,const node& b){
	return a.r<b.r;
}
bool check(LL a,LL b,LL c){
	if(b==1)return printf("0\n");
	a%=c,b%=c;
	LL cnt=0,base=1;
	for(LL g=gcd(a,c);g!=1;g=gcd(a,c)){
		if(b%g)return 0;
		b/=g,c/=g;
		base=base*(a/g)%c,++cnt;
		if(b==base)return printf("%lld\n",cnt);
	}
	LL m=ceil(sqrt(c)),tmp=1;
	for(LL i=1;i<=m;++i){
		tmp=tmp*a%c;
		lis[i]=node(i,tmp*b%c);
	}
	sort(lis+1,lis+1+m);
	for(LL i=1;i<=m;++i){
		base=base*tmp%c;
		node *p=lower_bound(lis+1,lis+m+1,node(0,base),cmpNode_for_lower_bound);
		if(p!=lis+m+1&&(*p).r==base)return printf("%lld\n",i*m-(*p).i+cnt);
	}
	return 0;
}
int main(){
	LL a,b,c;
	while(~scanf("%lld%lld%lld",&a,&b,&c)&&a&&b&&c){
		if(!check(a,c,b))puts("No Solution");
	}
	return 0;
}

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