結果

問題 No.1253 雀見椪
ユーザー okok
提出日時 2020-10-09 22:45:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,604 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 80,756 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 18:41:58
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 42 ms
4,376 KB
testcase_05 AC 41 ms
4,376 KB
testcase_06 AC 41 ms
4,376 KB
testcase_07 AC 42 ms
4,376 KB
testcase_08 AC 41 ms
4,376 KB
testcase_09 AC 42 ms
4,380 KB
testcase_10 AC 41 ms
4,376 KB
testcase_11 AC 41 ms
4,376 KB
testcase_12 AC 42 ms
4,380 KB
testcase_13 AC 42 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

long long power(long long x, long long n){
    long long ans = 1;
    for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD)
        if(n&1)ans*=x;
    return ans % MOD;
}
	
    
signed main(){
	cout<<fixed<<setprecision(10);
	
	int T;
    
    cin>>T;
    
    for(int _ = 0; _ < T; _++){
        int N;
        int G = 0, C = 1, P = 2;
        vector<int> H(3);
        int ans = 0;
        
        cin>>N;
        
        for(int i = 0; i < H.size(); i++){
            int A, B;
            
            cin>>A>>B;
            
            H[i] = (A * power(B, MOD-2)) % MOD;
            // cout<<"H "<<H[i]<<endl;
        }
        
        for(int i = 0; i < H.size(); i++){
            int a = i, b = (i+1)%H.size(), c = (i+2)%H.size();
            int hoge = 0;
            
            hoge = power((1+MOD-H[a])%MOD, N);
            hoge %= MOD;
            
            hoge = (MOD + hoge - power(H[b], N));
            hoge %= MOD;
            hoge = (MOD + hoge - power(H[c], N));
            hoge %= MOD;
            
            ans += hoge;
            ans %= MOD;
            // cout<<"hoge "<<hoge<<endl;
        }
        
        ans = (1 + MOD - ans) % MOD;
        
        cout<<ans<<endl;
    }
    
	return 0;
}
0