QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593658#4634. Factorucup-team3161#AC ✓488ms36356kbC++141.3kb2024-09-27 15:23:102024-09-27 15:23:11

Judging History

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

  • [2024-09-27 15:23:11]
  • 评测
  • 测评结果:AC
  • 用时:488ms
  • 内存:36356kb
  • [2024-09-27 15:23:10]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define int long long
using namespace std;

typedef vector<int>vi;
#define pb push_back

#define maxn 4000005
int pri[maxn],tot;
bool vis[maxn];

int sum[maxn];
void sieve(int n){
    vis[1]=1;
    For(i,2,n){
        if(!vis[i]){
            pri[++tot]=i;
        }
        For(j,1,tot){
            int x=i*pri[j];
            if(x>n)break;
            vis[x]=1;
            if(i%pri[j]==0)break;
        }
    }
    For(i,1,n) sum[i]=sum[i-1]+(!vis[i]);
}

int n,B;
int res;
void dfs(int u,int xs,int id){
    if(u>n) return;
    ++res;
  //  cout<<"add "<<u<<"\n";
    for(int i=id; i<=tot; ++i){
        if(u*pri[i]>n) break;
        if(pri[i]>xs+1) break;
        if(u*pri[i]*pri[i]>n){
            int r=min(xs+1,n/u);
            res+=sum[r]-sum[pri[i]-1];
            return;
        }
        int p=pri[i];
        int v=u,sv=1,pw=1;
        for(int j=1; ;++j){
            pw*=p;
            sv+=pw;
            v*=p;
            if(v>n)break;
            dfs(v,xs*sv,i+1);
        }
    }
}


signed main()
{
    cin>>n;
    B=sqrt(n)+1;
    sieve(3000005);
    dfs(1,1,1);
    cout<<res;
	return 0;
}

/*
1000000000000
50
1 2 4 6 8 12 16 18 20 24 28 30 32 36 40 42 48
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 35880kb

input:

10

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 16ms
memory: 36076kb

input:

20

output:

9

result:

ok single line: '9'

Test #3:

score: 0
Accepted
time: 11ms
memory: 34356kb

input:

50

output:

17

result:

ok single line: '17'

Test #4:

score: 0
Accepted
time: 13ms
memory: 34852kb

input:

6

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 15ms
memory: 34008kb

input:

87

output:

26

result:

ok single line: '26'

Test #6:

score: 0
Accepted
time: 11ms
memory: 36356kb

input:

609

output:

130

result:

ok single line: '130'

Test #7:

score: 0
Accepted
time: 14ms
memory: 34144kb

input:

5126

output:

806

result:

ok single line: '806'

Test #8:

score: 0
Accepted
time: 14ms
memory: 34644kb

input:

92180

output:

10905

result:

ok single line: '10905'

Test #9:

score: 0
Accepted
time: 14ms
memory: 35244kb

input:

984096

output:

95960

result:

ok single line: '95960'

Test #10:

score: 0
Accepted
time: 13ms
memory: 34692kb

input:

5744387

output:

494209

result:

ok single line: '494209'

Test #11:

score: 0
Accepted
time: 13ms
memory: 33948kb

input:

51133311

output:

3851066

result:

ok single line: '3851066'

Test #12:

score: 0
Accepted
time: 12ms
memory: 36312kb

input:

607519174

output:

40319008

result:

ok single line: '40319008'

Test #13:

score: 0
Accepted
time: 34ms
memory: 34924kb

input:

7739876803

output:

456270136

result:

ok single line: '456270136'

Test #14:

score: 0
Accepted
time: 86ms
memory: 34628kb

input:

80754680817

output:

4304423738

result:

ok single line: '4304423738'

Test #15:

score: 0
Accepted
time: 488ms
memory: 33932kb

input:

1000000000000

output:

48366248808

result:

ok single line: '48366248808'

Test #16:

score: 0
Accepted
time: 214ms
memory: 35236kb

input:

300000000000

output:

15176932897

result:

ok single line: '15176932897'

Test #17:

score: 0
Accepted
time: 294ms
memory: 36284kb

input:

500000000000

output:

24808936807

result:

ok single line: '24808936807'

Test #18:

score: 0
Accepted
time: 382ms
memory: 34244kb

input:

700000000000

output:

34300642547

result:

ok single line: '34300642547'

Test #19:

score: 0
Accepted
time: 412ms
memory: 36152kb

input:

790673894439

output:

38570752521

result:

ok single line: '38570752521'