QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298159#4634. FactordefyersTL 554ms15856kbC++141.4kb2024-01-05 19:01:522024-01-05 19:01:53

Judging History

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

  • [2024-01-05 19:01:53]
  • 评测
  • 测评结果:TL
  • 用时:554ms
  • 内存:15856kb
  • [2024-01-05 19:01:52]
  • 提交

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 cal(int p, LL sum) {
    int bot = p, top = prime.size() - 1, mid;
    while (bot <= top) {
        mid = (bot + top) / 2;
        if (prime[mid] <= sum) bot = mid + 1;
        else top = mid - 1;
    }
    return top - 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);
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 15768kb

input:

10

output:

5

result:

ok single line: '5'

Test #2:

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

input:

20

output:

9

result:

ok single line: '9'

Test #3:

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

input:

50

output:

17

result:

ok single line: '17'

Test #4:

score: 0
Accepted
time: 7ms
memory: 15856kb

input:

6

output:

4

result:

ok single line: '4'

Test #5:

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

input:

87

output:

26

result:

ok single line: '26'

Test #6:

score: 0
Accepted
time: 4ms
memory: 15808kb

input:

609

output:

130

result:

ok single line: '130'

Test #7:

score: 0
Accepted
time: 9ms
memory: 15856kb

input:

5126

output:

806

result:

ok single line: '806'

Test #8:

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

input:

92180

output:

10905

result:

ok single line: '10905'

Test #9:

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

input:

984096

output:

95960

result:

ok single line: '95960'

Test #10:

score: 0
Accepted
time: 22ms
memory: 15732kb

input:

5744387

output:

494209

result:

ok single line: '494209'

Test #11:

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

input:

51133311

output:

3851066

result:

ok single line: '3851066'

Test #12:

score: 0
Accepted
time: 554ms
memory: 15840kb

input:

607519174

output:

40319008

result:

ok single line: '40319008'

Test #13:

score: -100
Time Limit Exceeded

input:

7739876803

output:


result: