zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    02:找第一个只出现一次的字符
    11-Canvas
    07-jQuery
    06-JavaScript高级
    05-Web API
    03-京东项目
    剑与远征-兑换码
    04-JavaScript基础语法
    02-CSS
    01-HTML
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9522611.html
Copyright © 2011-2022 走看看