• 【POJ2891】Strange Way to Express Integers(拓展CRT)


    【POJ2891】Strange Way to Express Integers(拓展CRT)

    题面

    Vjudge
    板子题。

    题解

    拓展(CRT)模板题。

    #include<iostream>
    #include<cstdio>
    using namespace std;
    #define ll long long
    #define MAX 111111
    ll exgcd(ll a,ll b,ll &x,ll &y)
    {
    	if(!b){x=1,y=0;return a;}
    	ll d=exgcd(b,a%b,y,x);
    	y-=a/b*x;return d;
    }
    int n;
    ll m[MAX],a[MAX];
    int main()
    {
    	while(scanf("%d",&n)!=EOF)
    	{
    		bool fl=true;ll x,y;
    		for(int i=1;i<=n;++i)scanf("%lld%lld",&m[i],&a[i]);
    		for(int i=2;i<=n;++i)
    		{
    			ll d=exgcd(m[1],m[i],x,y),g=a[i]-a[1],t;
    			if(g%d){fl=false;break;}
    			x*=g/d;t=m[i]/d;x=(x%t+t)%t;
    			a[1]+=x*m[1];m[1]*=t;a[1]%=m[1];
    		}
    		if(!fl)puts("-1");
    		else printf("%lld
    ",(a[1]%m[1]+m[1])%m[1]);
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    EasyARM-Linux工具
    EasyARM-Linux文件系统
    EasyARM-Linux使用
    公差-PCBA
    novoton-USBDevice使用
    novoton-RTC使用
    novoton-ADC使用
    novoton-I2C使用
    novoton-timer使用
    novoton-usart使用
  • 原文地址:https://www.cnblogs.com/cjyyb/p/9316034.html
Copyright © 2020-2023  润新知