結果

問題 No.186 中華風 (Easy)
ユーザー latte0119latte0119
提出日時 2016-04-28 00:38:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,005 bytes
コンパイル時間 1,292 ms
コンパイル使用メモリ 155,628 KB
実行使用メモリ 12,028 KB
最終ジャッジ日時 2023-09-27 00:48:52
合計ジャッジ時間 2,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,020 KB
testcase_01 AC 25 ms
11,812 KB
testcase_02 AC 24 ms
11,976 KB
testcase_03 AC 24 ms
11,940 KB
testcase_04 AC 25 ms
11,836 KB
testcase_05 AC 25 ms
11,820 KB
testcase_06 AC 31 ms
11,932 KB
testcase_07 AC 25 ms
11,816 KB
testcase_08 AC 47 ms
11,868 KB
testcase_09 AC 42 ms
11,932 KB
testcase_10 AC 16 ms
11,888 KB
testcase_11 AC 73 ms
12,028 KB
testcase_12 AC 24 ms
11,776 KB
testcase_13 AC 25 ms
11,876 KB
testcase_14 AC 28 ms
11,876 KB
testcase_15 AC 28 ms
11,824 KB
testcase_16 AC 23 ms
11,944 KB
testcase_17 AC 24 ms
11,868 KB
testcase_18 AC 24 ms
11,820 KB
testcase_19 AC 16 ms
11,932 KB
testcase_20 AC 16 ms
11,836 KB
testcase_21 AC 16 ms
11,936 KB
testcase_22 AC 16 ms
11,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

//a*x-m*k=1
int extgcd(int a,int b,int &x,int &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    int g=extgcd(b,a%b,y,x);
    y-=a/b*x;
    return a;
    return g;
}

int X[3],Y[3];

vint get_prime(){
    vint f(1000000,1);
    vint prime;
    f[0]=f[1]=0;
    for(int i=2;i<1000000;i++){
        if(!f[i])continue;
        prime.pb(i);
        for(int j=i+i;j<1000000;j+=i)f[j]=0;
    }
    return prime;
}

signed main(){
    rep(i,3)cin>>X[i]>>Y[i];
    map<int,int>M;
    vint prime=get_prime();
    for(int p:prime){
        vint table(25,-1);
        rep(i,3){
            int t=1,c=0;
            while(Y[i]%t==0){
                if(table[c]==-1)table[c]=X[i]%t;
                else if(table[c]!=X[i]%t){
                    cout<<-1<<endl;
                    return 0;
                }

                t*=p;
                c++;
            }
        }
        int t=1,c=0;
        while(table[c]!=-1){
            t*=p;
            c++;
        }
        if(c>1)M[t/p]=table[c-1];
    }

    int ans=0;
    int m=1;
    each(i,M)m*=i->fi;

    each(i,M){
        int a=1;
        each(j,M){
            if(i->fi!=j->fi)a*=j->fi;
        }
        int inv,tmp;
        extgcd(a,i->fi,inv,tmp);
        inv=(inv+i->fi*i->fi)%i->fi;
        rep(j,i->se)ans=(ans+a*inv)%m;
    }
    ans%=m;
    if(ans==0)cout<<m<<endl;
    else cout<<ans<<endl;
    return 0;
}
0