QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#790750#9531. Weird CeilingJuliano1WA 12ms5100kbC++141.6kb2024-11-28 15:09:432024-11-28 15:09:44

Judging History

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

  • [2024-11-28 15:09:44]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:5100kb
  • [2024-11-28 15:09:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define int long long

using pii = pair<int, int>;

const int maxn = 1e6;
bool NotPrime[maxn + 5];
vector<int> Prime;

bool isPrime(int x) {
	if (x < maxn)return (!NotPrime[x]);
	if (x == 1 || x == 0)return 0;
	int R = sqrt(x) + 1;
	for (int i = 2; i <= R; i++) {
		if (x % i == 0)return 0;
	}
	return 1;
}

void ini() {
	NotPrime[0] = 1;
	NotPrime[1] = 1;
	for (int i = 2; i < maxn; i++) {
		if (NotPrime[i])continue;
		Prime.push_back(i);
		for (int j = 2; i * j < maxn; j++) {
			NotPrime[i * j] = 1;
		}
	}
}

// 质因子分解
vector<int> solve(int x) {
	vector<int> ans;
	for (int i = 0; i < Prime.size(); i++) {
		while (x % Prime[i] == 0) {
			ans.push_back(Prime[i]);
			x /= Prime[i];
		}
		if (x > maxn && isPrime(x)) { ans.push_back(x); break; }
	}
	return ans;
}



int func(int a, int b) {
	int i = b;
    if(isPrime(b))return a;
	while (i >= 2) {
		if (a % i == 0)return a / i;
		else i--;
	}
	return a;
}

int bino(int L0,int n) {
	int L = L0 - 1, R = n + 1;
	int val = func(n, L0);
	while (L + 1 != R) {
		int mid = (L + R) / 2;
		int now = func(n, mid);
		if (now == val) L = mid;
		else R = mid;
	}
	return L;
}


signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    ini();
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		int sum = 0;
		int L = 1;
		while (L <= n) {
			int R = bino(L, n); // 值为 func(n,L) 的区间
			sum += (R - L + 1) * func(n, L);
			L = R + 1;
		}
		cout << sum << endl;
	}

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 5100kb

input:

3
5
451
114514

output:

25
61711
2014613433

result:

wrong answer 1st lines differ - expected: '21', found: '25'