QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789779 | #9531. Weird Ceiling | Juliano1 | WA | 16ms | 5112kb | C++14 | 1.6kb | 2024-11-27 21:49:50 | 2024-11-27 21:49:51 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 16ms
memory: 5112kb
input:
3 5 451 114514
output:
25 61711 2014613433
result:
wrong answer 1st lines differ - expected: '21', found: '25'