poj2891:Strange Way to Express Integers

简介: 题目连接: 分明$excrt$就过了。 为什么还要仔细读题呢?    $qwq$ 反正我没读题然后被卡$long \ long +$输出格式错$……$总共$WA$了四次 怕不是要退役…… 上代码:   #include #include #include using na...

题目连接:

分明$excrt$就过了。

为什么还要仔细读题呢?   

$qwq$

反正我没读题然后被卡$long \ long +$输出格式错$……$总共$WA$了四次

怕不是要退役……

上代码:

 

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[100010],r[100010];
int n;
long long exgcd(long long a,long long b,long long &x,long long &y)
{
    if(b==0) return x=1,y=0,a;
    long long tmp=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return tmp;
}
long long slove()
{
    long long M=a[1],R=r[1],x,y,d;
    for(int i=2;i<=n;i++)
    {
        d=exgcd(M,a[i],x,y);
        if((R-r[i])%d!=0) return -1;
        x=(R-r[i])/d*x%a[i];
        R-=x*M;
        M=M/d*a[i];
        R%=M;
    }
    return (R%M+M)%M;
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
          scanf("%lld%lld",&a[i],&r[i]);
          printf("%lld\n",slove());
    }
    return 0;
}

 

相关文章
|
图形学
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
hdu1086 You can Solve a Geometry Problem too(判断线段相交)
81 0
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
56 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
56 0
|
算法 Go
HDU-1548,A strange lift(Dijkstra)
HDU-1548,A strange lift(Dijkstra)
|
人工智能
POJ 2533 Longest Ordered Subsequence
POJ 2533 Longest Ordered Subsequence
118 0
|
Go
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
114 0
LeetCode 172 Factorial Trailing Zeroes(阶乘后的零)(*)
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/50568854 翻译 给定一个整型n,返回n!后面的零的个数。
616 0
POJ 2533 Longest Ordered Subsequence
Description A numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence (a1, a2, …, aN) be ...
946 0