QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#431829 | #6854. Umamusume | heaksicn | AC ✓ | 1ms | 1204kb | C++17 | 1.2kb | 2024-06-06 09:59:44 | 2024-06-06 09:59:45 |
Judging History
answer
#include<cstdio>
typedef long long ll;
inline ll read(){
ll x=0;
int f=0,ch=0;
while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
return f?-x:x;
}
inline void write(ll x,char end='\n'){
if(x==0){
putchar('0');
putchar(end);
return;
}
if(x<0) putchar('-'),x=-x;
int ch[40]={0},cnt=0;
while(x){
ch[cnt++]=(int)(x%10);
x/=10;
}
while(cnt--) putchar(ch[cnt]+48);
putchar(end);
}
const ll mod=1e9+7;
ll n;
ll p;
inline ll fp(ll x,ll y){
ll s=1;
x=(x%mod+mod)%mod;
while(y){
if(y&1) s=s*x%mod;
x=x*x%mod;
y>>=1;
}
return s;
}
int main(){
int T=read();
while(T--){
n=read(),p=read();
if(n==0){
write(0);
continue;
}
if(n%2==0){
write(15ll*(n/2+1)%mod);
continue;
}
ll ans=15ll*(n/2+1)%mod;
ll r=n/6;
if(r>0){
ll p1=1-fp(1-p,r);
ll p2=1-fp(1-p,r)-fp(1-p,r-1)*p%mod*r%mod;
p1=(p1%mod+mod)%mod;
p2=(p2%mod+mod)%mod;
ll s=1-(1-p1)*(1-p2)%mod;
s=(s%mod+mod)%mod;
ans+=s*(7*p1%mod+6*(1-p1)%mod*p2%mod+3*(1-p1)%mod*(p1-p2)%mod)%mod;
}
ans=(ans%mod+mod)%mod;
write(ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 1204kb
input:
10000 0 105131995 1 117692 2 637385120 3 836440520 4 658724304 5 514051456 6 5451264 7 96052631 8 71936851 9 105586941 10 707337536 11 671801275 12 918938970 13 771170452 14 426363392 15 134193130 16 836236496 17 255916160 18 308620046 19 368680120 20 509918554 21 302946768 22 604853125 23 686238240...
output:
0 15 30 30 45 45 60 966860739 75 5485168 90 498799792 105 261269185 120 590717461 135 357724464 150 794226760 165 889940952 180 841259094 195 233653444 210 689164033 225 360831810 240 627716590 255 192741039 270 728030178 285 797951899 300 703150862 315 377396600 330 484194922 345 119266858 360 5188...
result:
ok 10000 lines