QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#79718 | #3724. Strange Prime | xzzduang | AC ✓ | 25ms | 5292kb | C++14 | 1.2kb | 2023-02-20 19:34:39 | 2023-02-20 19:34:42 |
Judging History
answer
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pii pair<int,int>
#define lowbit(x) ((x)&-(x))
#define popcount(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define umap unordered_map
#define all(x) x.begin(),x.end()
#define mk make_pair
#define pb push_back
#define ckmax(x,y) x=max(x,y)
#define ckmin(x,y) x=min(x,y)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define N 100005
#define int long long
using namespace std;
inline int read(){
int x=0,f=0; char ch=getchar();
while(!isdigit(ch)) f|=(ch==45),ch=getchar();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return f?-x:x;
}
const int mo=1e9+7,P=1e10+19;
inline void red(int &x){x>=mo?x-=mo:0;}
int n,a[N],ans,pre[N];
signed main(){
while(scanf("%lld",&n)!=EOF){
ans=0;
pre[0]=1;
for(int i=1;i<=n;++i) a[i]=read(),pre[i]=pre[i-1]*a[i]%mo;
int mul=1;
for(int i=n;i>=1;--i){
if((i-1)&1) red(ans+=mo-mul*pre[i-1]%mo);
else red(ans+=mul*pre[i-1]%mo);
mul=(P-a[i])%mo*mul%mo;
}
printf("%lld\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 25ms
memory: 5292kb
input:
10 2357 42596 7212 30898 43465 68984 60783 59520 53767 77560 10 39115 88080 83553 61736 90821 39690 13194 81396 38051 55993 10 95070 81321 71632 21071 10807 46105 66844 63678 47577 75132 10 43898 93215 26791 11849 61857 1423 76971 83489 52044 61325 10 22610 16613 90 53598 80110 42651 64942 67114 242...
output:
8747181 109223012 855771490 541976436 590061154 362989597 987338731 316507988 571293823 811262072 971678511 475746045 438611414 341241863 155506989 174497292 470085592 844919405 114498965 739370426 38587099 214008686 506810838 254574502 480440711 792847181 303917854 79001517 310250674 834963010 1907...
result:
ok 11305 numbers