結果
| 問題 |
No.1253 雀見椪
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 21:39:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,814 bytes |
| コンパイル時間 | 1,997 ms |
| コンパイル使用メモリ | 197,580 KB |
| 最終ジャッジ日時 | 2025-01-15 04:14:11 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:48:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | lint n; scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
main.cpp:51:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%d%d",&a,&b); p=mint(a)/b;
| ~~~~~^~~~~~~~~~~~~~
main.cpp:52:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | scanf("%d%d",&a,&b); q=mint(a)/b;
| ~~~~~^~~~~~~~~~~~~~
main.cpp:53:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d%d",&a,&b); r=mint(a)/b;
| ~~~~~^~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:58:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | int q; scanf("%d",&q); rep(_,q) solve();
| ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
class mint{
static const int MOD=1e9+7;
int x;
public:
mint():x(0){}
mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }
mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
mint& operator-=(const mint& m){ x-=m.x; if(x< 0) x+=MOD; return *this; }
mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
mint& operator/=(const mint& m){ return *this*=inverse(m); }
mint operator+(const mint& m)const{ return mint(*this)+=m; }
mint operator-(const mint& m)const{ return mint(*this)-=m; }
mint operator*(const mint& m)const{ return mint(*this)*=m; }
mint operator/(const mint& m)const{ return mint(*this)/=m; }
mint operator-()const{ return -x; }
friend mint inverse(const mint& m){
int a=m.x,b=MOD,u=1,v=0;
while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
return u;
}
friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=t; return is; }
friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
int to_int()const{ return x; }
};
mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }
mint pow(mint m,long long k){
mint res=1;
for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
return res;
}
void solve(){
lint n; scanf("%lld",&n);
mint p,q,r;
int a,b;
scanf("%d%d",&a,&b); p=mint(a)/b;
scanf("%d%d",&a,&b); q=mint(a)/b;
scanf("%d%d",&a,&b); r=mint(a)/b;
cout<<1-pow(p+q,n)-pow(q+r,n)-pow(r+p,n)+2*pow(p,n)+2*pow(q,n)+2*pow(r,n)<<'\n';
}
int main(){
int q; scanf("%d",&q); rep(_,q) solve();
return 0;
}