QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65725#1175. Bags of CandieseyiigjknRE 18ms3652kbC++14971b2022-12-03 12:56:222022-12-03 12:56:26

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 12:56:26]
  • 评测
  • 测评结果:RE
  • 用时:18ms
  • 内存:3652kb
  • [2022-12-03 12:56:22]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll solve(ll n)
{
	int sqn=sqrtl(n),m=0,tot=0;
	static int prime[400010];
	static ll blo[700010],f[700010];
	static bool npri[400010];
	npri[1]=1;
	for(int i=2;i<=sqn;i++)
	{
		if(!npri[i]) prime[++m]=i;
		for(int j=1;j<=m && i*prime[j]<=sqn;j++)
		{
			npri[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	for(ll i=1,j;i<=n;i=j+1) j=n/(n/i),blo[++tot]=n/i;
	auto getid=[&](ll x)->int{return x<=sqn?tot-x+1:n/x;};
	for(int i=1;i<=tot;i++) f[i]=blo[i]-1;
	for(int i=1;i<=m;i++)
		for(int j=1;blo[j]>=prime[i]*prime[i];j++)
			f[j]-=f[getid(blo[j]/prime[i])]-i+1;
	ll ans=n-(n-1-(f[getid(n)]-f[getid(n/2)]))/2;
	memset(prime+1,0,sizeof(int)*m);
	memset(blo+1,0,sizeof(ll)*tot);
	memset(f+1,0,sizeof(ll)*tot);
	memset(npri+1,0,sizeof(bool)*sqn);
	return ans;
}
int main()
{
	int T;
	ll n;
	cin>>T;
	while(T--) scanf("%lld",&n),printf("%lld\n",solve(n));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3488kb

input:

2
4
9

output:

3
6

result:

ok 2 number(s): "3 6"

Test #2:

score: 0
Accepted
time: 3ms
memory: 3528kb

input:

5
2
3
4
5
6

output:

2
3
3
4
4

result:

ok 5 number(s): "2 3 3 4 4"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

5
1111
2018
3333
4006
5555

output:

599
1078
1772
2128
2942

result:

ok 5 number(s): "599 1078 1772 2128 2942"

Test #4:

score: 0
Accepted
time: 18ms
memory: 3652kb

input:

5
26666666
10000000
23456789
27777777
24444442

output:

13730373
5158034
12080298
14301448
12588059

result:

ok 5 number(s): "13730373 5158034 12080298 14301448 12588059"

Test #5:

score: -100
Runtime Error

input:

5
47890123456
12345678901
96666666669
85555555558
100000000000

output:


result: