結果
| 問題 |
No.1253 雀見椪
|
| ユーザー |
東前頭十一枚目
|
| 提出日時 | 2020-10-10 16:41:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,000 ms |
| コード長 | 2,159 bytes |
| コンパイル時間 | 1,947 ms |
| コンパイル使用メモリ | 197,480 KB |
| 最終ジャッジ日時 | 2025-01-15 06:22:04 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
fint64 x;
ModInt():x(0){}
ModInt(fint64 x):
x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
{}
// 負号
ModInt operator -() const{
return ModInt(-x);
}
// 加算
ModInt &operator +=(const ModInt &rhs){
x+=rhs.x;
if(x>=MOD) x-=MOD;
return (*this);
}
ModInt operator +(const ModInt &rhs) const{
return ModInt(*this)+=rhs;
}
// 減算
ModInt &operator -=(const ModInt &rhs){
x+=MOD-rhs.x;
if(x>=MOD) x-=MOD;
return (*this);
}
ModInt operator -(const ModInt &rhs) const{
return ModInt(*this)-=rhs;
}
// 乗算
ModInt &operator *=(const ModInt &rhs){
x*=rhs.x;
if(x>=MOD) x%=MOD;
return (*this);
}
ModInt operator *(const ModInt &rhs) const{
return ModInt(*this)*=rhs;
}
// 除算
ModInt &operator /=(const ModInt &rhs){
(*this)*=rhs.inverse();
return (*this);
}
ModInt operator /(const ModInt &rhs) const{
return ModInt(*this)/=rhs;
}
// 等号
bool operator ==(const ModInt &rhs){
return x==rhs.x;
}
bool operator !=(const ModInt &rhs){
return x!=rhs.x;
}
// 累乗
ModInt pow(fint64 n) const{
fint64 tmp=x;
fint64 ret=1;
while(n>0){
if(n&1) ret=ret*tmp%MOD;
tmp=tmp*tmp%MOD;
n>>=1ll;
}
return ModInt(ret);
}
// 逆元
ModInt inverse() const{
fint64 a=x,b=MOD,s=1,t=0;
while(b>0){
fint64 u=a/b;
a-=u*b;
s-=u*t;
swap(a,b);
swap(s,t);
}
return ModInt(s);
}
// 入出力
friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
fint64 x; lhs>>x;
rhs=ModInt<MOD>(x);
return lhs;
}
friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
return lhs<<rhs.x;
}
};
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
int main() {
int t; cin >> t;
while(t--) {
int64_t n, ag, bg, ac, bc, ap, bp;
cin >> n >> ag >> bg >> ac >> bc >> ap >> bp;
mint g = (mint)ag / bg;
mint c = (mint)ac / bc;
mint p = (mint)ap / bp;
mint ans = 1;
ans -= (g + c).pow(n) - g.pow(n) - c.pow(n);
ans -= (c + p).pow(n) - c.pow(n) - p.pow(n);
ans -= (p + g).pow(n) - p.pow(n) - g.pow(n);
cout << ans << '\n';
}
return 0;
}
東前頭十一枚目