QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234842 | #6640. Talk That Talk | ugly2333 | TL | 640ms | 29892kb | C++20 | 1.2kb | 2023-11-01 23:42:09 | 2023-11-01 23:42:09 |
Judging History
answer
//Δ_J
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
typedef __int128 i128;
const int N = 2222222;
int n,a[N],b[N],c[N];
LL p;
LL fpow(LL x,LL y){
LL z=1;
while(y){
if(y&1)
z=(i128)z*x%p;
x=(i128)x*x%p;
y>>=1;
}
return z;
}
LL geta(LL x){
return fpow(x,(p-1)/2)==1;
}
LL solve(){
int i;
LL s=0;
for(i=1;i<=n*2;i++)
c[i]=c[i-1]+a[i];
for(i=1;i<=n;i++)
if(!a[i])
s+=c[i+n]-c[i+i];
for(i=1;i<=n;i++)
if(!b[i])
s+=c[n-i];
c[1]=b[1];
for(i=2;i<=n;i++)
c[i]=c[i-2]+b[i];
for(i=2;i<=n*2;i++)
if(!a[i])
s+=c[min(i-2,n*2-i)];
return s;
}
int main(){
int T,i;
LL s;
scanf("%d",&T);
while(T--){
scanf("%lld%d",&p,&n);
n=min((LL)n,(p-1)/2);
if(p%4==1){
s=p-2-(p-1)/2;
if(geta(2))
s=(s-1)/2;
else
s=(s+1)/2;
s--;
}
else{
s=(p-1)/2;
if(geta(2))
s=(s-1)/2;
else
s=(s+1)/2;
s--;
}
s*=n;//cout<<s<<endl;
for(i=1;i<=n*2;i++)
a[i]=geta(i);
for(i=1;i<=n*2;i++)
b[i]=a[i]^(p%4==3);
s-=(LL)n*(n-1);
s+=solve();
swap(a,b);
s+=solve();
printf("%lld\n",s);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 640ms
memory: 29892kb
input:
7 7 32 13 1 13 2 67 11 2003 44 1000003 1984 999999999989 987654
output:
0 2 2 146 21510 495014784 246913256130162788
result:
ok 7 numbers
Test #2:
score: -100
Time Limit Exceeded
input:
11696 5 1 5 2 7 1 7 2 7 3 11 1 11 2 11 3 11 4 11 5 13 1 13 2 13 3 13 4 13 5 13 6 17 1 17 2 17 3 17 4 17 5 17 6 17 7 17 8 19 1 19 2 19 3 19 4 19 5 19 6 19 7 19 8 19 9 23 1 23 2 23 3 23 4 23 5 23 6 23 7 23 8 23 9 23 10 23 11 29 1 29 2 29 3 29 4 29 5 29 6 29 7 29 8 29 9 29 10 29 11 29 12 29 13 29 14 31...
output:
0 0 0 0 0 2 4 4 6 6 2 2 4 4 4 4 2 4 4 6 6 6 8 8 4 8 10 12 16 18 18 20 20 4 8 12 16 20 22 24 24 24 24 24 6 12 18 24 24 28 32 36 40 40 40 44 44 44 6 12 18 22 26 32 34 36 42 44 44 46 46 46 46 8 14 22 26 32 38 42 44 52 54 56 60 62 62 64 64 64 64 8 16 20 28 34 38 44 52 54 56 60 64 66 68 70 74 74 74 76 76...