QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298165#4634. FactordefyersTL 1026ms35592kbC++141.5kb2024-01-05 19:08:412024-01-05 19:08:41

Judging History

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

  • [2024-01-05 19:08:41]
  • 评测
  • 测评结果:TL
  • 用时:1026ms
  • 内存:35592kb
  • [2024-01-05 19:08:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long

vector<int> prime;
void find_prime(int n) {
    vector<int> lp(n, 0);
    for (int i = 2; i <= n; i++) {
        if (lp[i] == 0) { lp[i] = i; prime.push_back(i); }
        for (int j = 0; i * prime[j] <= n; j++) {
            lp[i * prime[j]] = prime[j];
            if (prime[j] == lp[i]) break; } } return;
}

LL n;
LL ans;
LL toprime[4000005];

LL cal(int p, LL sum) {
    sum = min(sum, (LL)4e6);
    if (toprime[sum] < p) return 0;
    //cout << "(" << sum << " " << toprime[sum] << ") ";
    return toprime[sum] - p + 1;
}

void f(LL sum, LL num, int pl) {
	ans += cal(pl, min(sum + 1, num));
	if (num < prime[pl] * prime[pl]) return;
	//cout << "num=" << num << endl;
	for (int i = pl; i < prime.size(); i++) {
		if (num < prime[i] || sum + 1 < prime[i]) break;
		LL tmp = prime[i];
		LL add = 1 + prime[i];
		while (tmp <= num) {
		    if (tmp != prime[i]) ans++;
			f(min((LL)1e7, sum * add), num / tmp, i + 1);
			tmp *= prime[i];
			add += tmp;
			add = min(add, (LL)1e7);
		}
	}
}

void solve() {
	cin >> n;
	ans = 1;
	f(1, n, 0); // prime[0] = 2
	cout << ans << "\n";
	return;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
   	cout << fixed << setprecision(10);
	find_prime(3e6);
	int p = 0;
	for (int i = 2; i <= 4e6; i++) {
	    while (p < prime.size() && prime[p + 1] <= i) p++;
	    toprime[i] = p;
	}
	solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 21ms
memory: 35380kb

input:

10

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 10ms
memory: 35404kb

input:

20

output:

9

result:

ok single line: '9'

Test #3:

score: 0
Accepted
time: 21ms
memory: 35396kb

input:

50

output:

17

result:

ok single line: '17'

Test #4:

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

input:

6

output:

4

result:

ok single line: '4'

Test #5:

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

input:

87

output:

26

result:

ok single line: '26'

Test #6:

score: 0
Accepted
time: 8ms
memory: 35268kb

input:

609

output:

130

result:

ok single line: '130'

Test #7:

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

input:

5126

output:

806

result:

ok single line: '806'

Test #8:

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

input:

92180

output:

10905

result:

ok single line: '10905'

Test #9:

score: 0
Accepted
time: 17ms
memory: 35380kb

input:

984096

output:

95960

result:

ok single line: '95960'

Test #10:

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

input:

5744387

output:

494209

result:

ok single line: '494209'

Test #11:

score: 0
Accepted
time: 27ms
memory: 35188kb

input:

51133311

output:

3851066

result:

ok single line: '3851066'

Test #12:

score: 0
Accepted
time: 105ms
memory: 35188kb

input:

607519174

output:

40319008

result:

ok single line: '40319008'

Test #13:

score: 0
Accepted
time: 1026ms
memory: 35140kb

input:

7739876803

output:

456270136

result:

ok single line: '456270136'

Test #14:

score: -100
Time Limit Exceeded

input:

80754680817

output:


result: