結果

問題 No.1253 雀見椪
ユーザー face4
提出日時 2020-10-10 20:14:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 699 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 64,384 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:54:39
合計ジャッジ時間 3,866 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int t;
    cin >> t;
    while(t--){
        ll n, a[3], b[3];
        cin >> n;
        for(int i = 0; i < 3; i++)  cin >> a[i] >> b[i], a[i] = a[i]*modpow(b[i],mod-2)%mod;
        ll ans = 0;
        for(int i = 0; i < 3; i++)  (ans += modpow(a[i]+a[(i+1)%3], n)-modpow(a[i], n)-modpow(a[(i+1)%3], n)+mod+mod) %= mod;
        cout << (1-ans+mod)%mod << endl;
    }
    return 0;
}
0