• 【UOJ 676】三数同余


    【题目描述】:

    已知三个正整数 a,b,c。

    现有一个大于1的整数x,将其作为除数分别除a,b,c,得到的余数相同。

    请问满足上述条件的x的最大值是多少?

    数据保证x有解。

    【输入描述】:

    一行,三个正整数a,b,c,两个整数之间用一个空格隔开。

    【输出描述】:

    一个整数,即满足条件的x的最大值。

    【样例输入】:

    300 262 205

    【样例输出】:

    19

    【时间限制、数据范围及描述】:

    时间:1s 空间:64M

    对于 30%的数据:1<a,b,c<10^6

    对于100%的数据:1<a,b,c<10^18

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const int N=1000003;
    ll a,b,c; 
    ll work(ll a,ll b,ll c){
        ll d=max(a,max(b,c));
        for(ll i=d;i>=1;i--)
            if( (a%i==b%i) &&(c%i==b%i) )
            return i;
        return 0;
    }
    
    ll gcd(ll a,ll b){
        if(b==0) return a;
        return gcd(b,a%b);
    } 
    ll maxx(ll a,ll b){
        if(a>b) return a;
        else return b;
    }
    ll minn(ll a,ll b){
        if(a<b) return a;
        else return b;
    }
    int main(){
        freopen("resisame.in","r",stdin);
        freopen("resisame.out","w",stdout);
        cin>>a>>b>>c; 
    //    if(a<=N && b<=N && c<=N){
    //        printf("%lld
    ",work(a,b,c));
    //        return 0;
    //    }
        ll aa=maxx(a,max(b,c));
        ll bb=minn(a,min(b,c));
        ll cc;
        if(a!=aa && a!=bb) cc=a;
        if(b!=aa && b!=bb) cc=b;
        if(c!=aa && c!=bb) cc=c;
        ll ans=gcd(aa-bb,aa-cc);
        printf("%lld",ans);
        //printf("%d %d %d",a%ans,b%ans,c%ans);
        return 0;
    }
  • 相关阅读:
    tslib編译和安装
    Web服务器的工作原理
    激励一生的六个经典故事
    VS2010中创建安装项目
    vue中img标签图片 加载时 与 加载失败 的处理方法
    Vue函数式组件的应用
    深入浅出Object.defineProperty()
    重学Git(一)
    backgroundblendmode
    箭头流程图前端实现
  • 原文地址:https://www.cnblogs.com/wuhu-JJJ/p/13874195.html
Copyright © 2020-2023  润新知