UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211855#3809. 平方drdilyor255729ms1180kbC++111.4kb2024-10-07 16:46:352024-10-07 18:37:18

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
const int mod=1e9+7;
int n;
int a[10005];
bool p[10005];
int cnt[10005];
int qkp(int b,int pw){
	int r=1;
	while(pw){
		if(pw&1)(r*=b)%=mod;
		pw/=2;
		(b*=b)%=mod;
	}
	return r;
}
int w[10005],o[10005],e[10005];
int l;
int merge(int x,int y){
	x*=y;
	int r=1;
	for(int j=2;j<=n;j++){
		if(!p[j]){
			int c=0;
			while(x%j==0)x/=j,c++;
			if(c&1)r*=j;
		}
	}
	return r;
}
signed main(){
	n=read();
	for(int i=2;i<=n;i++){
		if(!p[i]){
			for(int j=i*2;j<=n;j+=i)p[j]=1;
		}
	}
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++){
		int x=i;
		int r=1;
		for(int j=2;j<=n;j++){
			if(!p[j]){
				int c=0;
				while(x%j==0)x/=j,c++;
				if(c&1)r*=j;
			}
		}
		cnt[r]+=a[i];
	}
	int coef=qkp(2,cnt[1]);
	for(int i=2;i<=n;i++){
		if(!cnt[i])continue;
		w[++l]=i;
		coef*=qkp(2,cnt[i]-1);coef%=mod;
	}
	int p=0;
	for(int i=0;i<(1<<l);i++){
		int tmp=1;
		for(int j=1;j<=l;j++)if(i&(1<<(j-1)))tmp=merge(tmp,w[j]);
		if(tmp==1)p++;
	}
	coef*=p;coef%=mod;
	cout<<(coef-1+mod)%mod<<"\n";
	return 0;
}
//look at my code
//my code is amazing

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 1176kb

input:

12
2 2 1 2 2 2 1 2 1 2 2 1

output:

32767

result:

ok single line: '32767'

Test #2:

score: 5
Accepted
time: 11ms
memory: 1180kb

input:

21
6071 63571 70449 84192 57749 63236 82243 16019 98823 69250 95932 44671 76920 1666 56759 63797 648...

output:

907130596

result:

ok single line: '907130596'

Test #3:

score: 5
Accepted
time: 11ms
memory: 1176kb

input:

21
78070 53308 73131 49008 73223 91635 38770 85297 83190 39966 6535 12302 86455 15079 69516 35452 51...

output:

805058470

result:

ok single line: '805058470'

Test #4:

score: 5
Accepted
time: 2853ms
memory: 1176kb

input:

33
35253 15438 45783 71029 3464 55562 30300 98250 91277 30754 11674 56865 29791 79077 23593 76795 12...

output:

417265909

result:

ok single line: '417265909'

Test #5:

score: 5
Accepted
time: 2844ms
memory: 1180kb

input:

33
14031 20789 70420 49867 25529 65501 21352 91592 59302 81424 15091 80896 77254 33600 96383 93040 5...

output:

159573572

result:

ok single line: '159573572'

Test #6:

score: 0
Wrong Answer
time: 5ms
memory: 1180kb

input:

69
2277 90628 50971 84997 47731 58491 19590 74491 87059 48528 19450 65425 86171 98793 53240 80874 99...

output:

18972838

result:

wrong answer 1st lines differ - expected: '707904026', found: '18972838'

Test #7:

score: 0
Wrong Answer
time: 5ms
memory: 1180kb

input:

69
6929 54762 47684 30491 63013 85382 58761 85482 54656 20874 52114 13167 68239 91992 60774 5725 631...

output:

958189858

result:

wrong answer 1st lines differ - expected: '60461118', found: '958189858'

Test #8:

score: 0
Time Limit Exceeded

input:

139
62883 20064 72746 22914 47638 63229 46693 77251 78236 615 24875 13385 17824 91084 216 55070 9832...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

139
19629 38452 31587 31200 1869 6696 18434 59574 94450 11252 30525 87152 78094 86067 98721 62927 56...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

312
70754 34698 434 7024 81418 37867 43301 45062 55942 77685 1947 49600 54159 99924 53272 31135 1756...

output:


result:


Test #11:

score: 0
Time Limit Exceeded

input:

312
12238 62101 38093 35253 92243 46623 83863 23871 48000 1097 1388 64677 89840 48843 14477 63405 21...

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

312
65902 15679 97624 23389 1670 29206 1712 34607 36006 72210 34479 63586 47142 46925 66200 62562 94...

output:


result:


Test #13:

score: 0
Time Limit Exceeded

input:

1234
46686 11939 57055 17773 24469 47283 582 90402 27842 94874 61013 1020 28443 75832 33798 22291 20...

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

1234
89657 93796 12385 56406 36479 74685 90947 11817 80881 79329 14528 23593 77641 70991 30841 27849...

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

1234
26692 21448 75529 67905 19536 62310 42976 55776 64574 65478 36252 31679 45062 47707 31881 88564...

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

4021
66995 6713 36815 57369 44032 62055 95975 29509 73258 33818 23360 74155 41951 4813 39228 48076 9...

output:


result:


Test #17:

score: 0
Time Limit Exceeded

input:

4021
78965 97182 64913 97851 50137 84422 11931 50279 43224 57995 41056 98897 21489 38558 18113 3233 ...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

4021
60148 5548 69611 73408 50792 67625 97878 48790 50897 56905 13105 19252 35169 541 2594 94014 514...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

5123
77728 68936 11371 45534 25976 11734 48963 5558 35198 28029 2396 95361 74072 72459 81788 38528 6...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

5123
34879 51531 20100 53943 82673 4948 38474 13579 19262 38324 28806 50542 93369 76646 80881 16857 ...

output:


result: