| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我擦!2891 又是Pres error! 求救大牛看下代码 哪里输入格式不对!!!#include<iostream>
using namespace std;
#include<stdio.h>
long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
long long ans,t;
if(b==0){
x=1;
y=0;
return a;}
ans=extend_gcd(b,a%b,x,y);
t=x;
x=y;
y=t-(a/b)*y;
return ans;
}
int main()
{
long long k,a1,r1,a2,r2,x,y,gcd,t;
bool flag;
while(cin>>k)
{
scanf("%lld %lld",&a1,&r1);
if(k==1)
{
if(a1<=r1)
cout<<-1;
else cout<<r1;
}
k--;
flag=0;
while(k--)
{
scanf("%lld %lld",&a2,&r2);
if(a2<=r2)flag=1;
gcd=extend_gcd(a1,a2,x,y);
if((r2-r1)%gcd!=0)flag=1;
else
{
t=a2/gcd;
x=((r2-r1)/gcd*x%t+t)%t;
r1=x*a1+r1;
a1=a1*a2/gcd;//lcm(a1,a2);
r1=(r1%a1+a1)%a1;
}
}
if(flag)
cout<<-1;
else
cout<<r1;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator