QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#48059#4634. Factorsjc061031AC ✓1186ms84416kbC++23986b2022-09-11 14:31:422022-09-11 14:31:43

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-11 14:31:43]
  • Judged
  • Verdict: AC
  • Time: 1186ms
  • Memory: 84416kb
  • [2022-09-11 14:31:42]
  • Submitted

answer

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
using namespace std;

int cnt,pri[10000010],vis[10000010],sum[10000010];
long long n,ans=1ll;

inline void init()
{
	for(int i=2;i<=10000000;i++){
		if(!vis[i]) pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<=10000000;j++){
			vis[i*pri[j]]=1;
			if(i%pri[j]==0) break;
		}
	}
	sum[1]=0;
	for(int i=2;i<=10000000;i++) sum[i]=sum[i-1]+(!vis[i]);
}

inline void dfs(int lvl,long long S,long long V,bool flag)
{
	if(pri[lvl]>S+1) return;
	if(V*pri[lvl]>n) return;
	if(flag) ans+=1ll*(sum[min(S+1,n/V)]-sum[pri[lvl]-1]);
	if(V*pri[lvl]*pri[lvl]<=n){
		long long now1=1,now2=1;
		for(int i=0;V*now2<=n;i++){
			if(i>=2) ans++;
			dfs(lvl+1,S*now1,V*now2,(i>0));
			now2=now2*pri[lvl];now1+=now2;
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	init();
	cin>>n;
	dfs(1,1,1,1);
	cout<<ans<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 104ms
memory: 84328kb

input:

10

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 110ms
memory: 84324kb

input:

20

output:

9

result:

ok single line: '9'

Test #3:

score: 0
Accepted
time: 98ms
memory: 84292kb

input:

50

output:

17

result:

ok single line: '17'

Test #4:

score: 0
Accepted
time: 68ms
memory: 84356kb

input:

6

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 73ms
memory: 84292kb

input:

87

output:

26

result:

ok single line: '26'

Test #6:

score: 0
Accepted
time: 78ms
memory: 84292kb

input:

609

output:

130

result:

ok single line: '130'

Test #7:

score: 0
Accepted
time: 81ms
memory: 84304kb

input:

5126

output:

806

result:

ok single line: '806'

Test #8:

score: 0
Accepted
time: 70ms
memory: 84304kb

input:

92180

output:

10905

result:

ok single line: '10905'

Test #9:

score: 0
Accepted
time: 71ms
memory: 84352kb

input:

984096

output:

95960

result:

ok single line: '95960'

Test #10:

score: 0
Accepted
time: 75ms
memory: 84360kb

input:

5744387

output:

494209

result:

ok single line: '494209'

Test #11:

score: 0
Accepted
time: 65ms
memory: 84324kb

input:

51133311

output:

3851066

result:

ok single line: '3851066'

Test #12:

score: 0
Accepted
time: 87ms
memory: 84360kb

input:

607519174

output:

40319008

result:

ok single line: '40319008'

Test #13:

score: 0
Accepted
time: 104ms
memory: 84372kb

input:

7739876803

output:

456270136

result:

ok single line: '456270136'

Test #14:

score: 0
Accepted
time: 247ms
memory: 84336kb

input:

80754680817

output:

4304423738

result:

ok single line: '4304423738'

Test #15:

score: 0
Accepted
time: 1186ms
memory: 84404kb

input:

1000000000000

output:

48366248808

result:

ok single line: '48366248808'

Test #16:

score: 0
Accepted
time: 518ms
memory: 84336kb

input:

300000000000

output:

15176932897

result:

ok single line: '15176932897'

Test #17:

score: 0
Accepted
time: 710ms
memory: 84408kb

input:

500000000000

output:

24808936807

result:

ok single line: '24808936807'

Test #18:

score: 0
Accepted
time: 883ms
memory: 84416kb

input:

700000000000

output:

34300642547

result:

ok single line: '34300642547'

Test #19:

score: 0
Accepted
time: 947ms
memory: 84388kb

input:

790673894439

output:

38570752521

result:

ok single line: '38570752521'