• 51Nod


    直接就是板子了,但是呢,我去了个重。

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<string>
    #include<set>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<list>
    #include<cmath>
    #include<cstring>
    #include<map>
    #include<stack>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define maxn 1005
    #define ull unsigned long long
    #define ll long long
    #define hashmod 99999839
    #define mod 9997
    struct func{
        ll p;
        ll y;
    }a[maxn];
    int n;
    ll m[maxn],y[maxn];
    bool cmp(const func& a,const func& b){
        if(a.p != b.p) return a.p < b.p;
        return a.y < b.y;
    }
    ll excgcd(ll a,ll b,ll& x,ll& y){
        if(!b){x = 1,y = 0;return a;}
        ll g = excgcd(b,a % b,x,y);
        ll t = x;
        x = y;
        y = t - a/b * y;
        return g;
    }
    void check(){
        sort(a + 1,a + n + 1,cmp);
        int j = 2;
        for(int i = 2;i <= n;++i){
            if(a[i].p == a[i-1].p && a[i].y == a[i-1].y) continue;
            a[j] = a[i];
            ++j;
        }
        n = j - 1;
    }
    void solve(){
        ll M = 1,x = 0,y = 0,ans = 0;//[m_1,m_2,...,m_n]
        for(int i = 1;i <= n;++i) M *= a[i].p;
        for(int i = 1;i <= n;++i){
            m[i] = M / a[i].p;
            ll g = excgcd(m[i],a[i].p,x,y);
            x = x + (abs(x)/(a[i].p/g) + 1) * (a[i].p/g);
            x = x % (a[i].p/g);//将x扩展为正数
            ans = ans + x * m[i] * a[i].y;
            if(ans >= M) ans %= M;
        }
        printf("%lld
    ",ans);
    }
    int main(){
    //    freopen("a.in","r",stdin);
    //    freopen("b.out","w",stdout);
        while(~scanf("%d",&n)){
            for(int i = 1;i <= n;++i) scanf("%lld%lld",&a[i].p,&a[i].y);
            check();
            solve();
        }
        return 0;
    }
  • 相关阅读:
    解决vs code just-in-time报错的方法
    c++ 右值引用
    c++11 知识点
    ip路由名词介绍&琐碎知识
    第二次结对作业
    软工程第三次作业
    第二次作业
    软件工程第一次作业
    理解Object.defineProperty()
    concat()拷贝的局限性
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9522611.html
Copyright © 2020-2023  润新知