QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621559#4634. FactorCrysflyAC ✓518ms36240kbC++141.3kb2024-10-08 15:22:232024-10-08 15:22:25

Judging History

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

  • [2024-10-08 15:22:25]
  • 评测
  • 测评结果:AC
  • 用时:518ms
  • 内存:36240kb
  • [2024-10-08 15:22:23]
  • 提交

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: 16ms
memory: 35860kb

input:

10

output:

5

result:

ok single line: '5'

Test #2:

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

input:

20

output:

9

result:

ok single line: '9'

Test #3:

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

input:

50

output:

17

result:

ok single line: '17'

Test #4:

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

input:

6

output:

4

result:

ok single line: '4'

Test #5:

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

input:

87

output:

26

result:

ok single line: '26'

Test #6:

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

input:

609

output:

130

result:

ok single line: '130'

Test #7:

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

input:

5126

output:

806

result:

ok single line: '806'

Test #8:

score: 0
Accepted
time: 20ms
memory: 35024kb

input:

92180

output:

10905

result:

ok single line: '10905'

Test #9:

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

input:

984096

output:

95960

result:

ok single line: '95960'

Test #10:

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

input:

5744387

output:

494209

result:

ok single line: '494209'

Test #11:

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

input:

51133311

output:

3851066

result:

ok single line: '3851066'

Test #12:

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

input:

607519174

output:

40319008

result:

ok single line: '40319008'

Test #13:

score: 0
Accepted
time: 31ms
memory: 34588kb

input:

7739876803

output:

456270136

result:

ok single line: '456270136'

Test #14:

score: 0
Accepted
time: 88ms
memory: 35960kb

input:

80754680817

output:

4304423738

result:

ok single line: '4304423738'

Test #15:

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

input:

1000000000000

output:

48366248808

result:

ok single line: '48366248808'

Test #16:

score: 0
Accepted
time: 211ms
memory: 34664kb

input:

300000000000

output:

15176932897

result:

ok single line: '15176932897'

Test #17:

score: 0
Accepted
time: 305ms
memory: 34272kb

input:

500000000000

output:

24808936807

result:

ok single line: '24808936807'

Test #18:

score: 0
Accepted
time: 395ms
memory: 34408kb

input:

700000000000

output:

34300642547

result:

ok single line: '34300642547'

Test #19:

score: 0
Accepted
time: 430ms
memory: 35584kb

input:

790673894439

output:

38570752521

result:

ok single line: '38570752521'