QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790058 | #9531. Weird Ceiling | Juliano1 | RE | 47ms | 6148kb | C++14 | 2.7kb | 2024-11-28 00:14:44 | 2024-11-28 00:14:44 |
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;
vector<bool> is_prime; // For larger values of x beyond maxn
bool isPrime(int x) {
if (x < maxn) return !NotPrime[x];
return is_prime[x]; // For large x
}
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 = i * i; j < maxn; j += i) {
NotPrime[j] = 1;
}
}
// Initialize is_prime for large values up to a reasonable limit
is_prime.resize(1e7 + 5, true); // Adjust the upper bound based on your needs
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= 1e7; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= 1e7; j += i) {
is_prime[j] = false;
}
}
}
}
// 质因子分解
vector<pii> solve(int x) {
map<int, int> cnt;
for (int i = 0; i < Prime.size(); i++) {
while (x % Prime[i] == 0) {
cnt[Prime[i]]++;
x /= Prime[i];
}
if (x == 1) break;
if (x < maxn) continue;
if (isPrime(x)) {
cnt[x]++;
break;
}
}
if (x > 1) {
cnt[x]++; // If x is prime and greater than maxn
}
vector<pii> ans;
for (auto it : cnt)
ans.push_back({it.first, it.second});
return ans;
}
// 生成所有因数
void get_factor(vector<pii> cnt, set<int>& ans, int idx, int val) {
if (idx == cnt.size()) return;
int now = cnt[idx].first;
int sum = cnt[idx].second;
int pwr = 1;
for (int i = 0; i <= sum; i++) {
val *= pwr;
ans.insert(val);
get_factor(cnt, ans, idx + 1, val);
val /= pwr;
pwr *= now;
}
}
int func(int a, int b, set<int>& st) {
auto it = st.upper_bound(b);
it--;
return a / (*it);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ini();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
// 获取n的质因子分解
auto cnt = solve(n);
set<int> st;
st.insert(1);
// 生成所有因数
get_factor(cnt, st, 0, 1);
int sum = 1;
int last = *st.begin();
// 计算每个因数对的贡献
for (auto it : st) {
sum += (it - last) * n / last;
last = it;
}
cout << sum << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 41ms
memory: 6148kb
input:
3 5 451 114514
output:
21 10251 7075858
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 47ms
memory: 5984kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
1 3 7 9 21 16 43 25 37 36 111 41 157 64 71 65 273 73 343 86 113 144 507 101 201 196 163 134 813 137 931 161 221 324 295 169 1333 400 287 205 1641 218 1807 254 277 576 2163 241 589 301 443 326 2757 298 507 317 533 900 3423 315 3661 1024 439 385 625 386 4423 494 737 437 4971 394 5257 1444 551 590 969 ...
result:
ok 1000 lines
Test #3:
score: -100
Runtime Error
input:
1000 999999001 999999002 999999003 999999004 999999005 999999006 999999007 999999008 999999009 999999010 999999011 999999012 999999013 999999014 999999015 999999016 999999017 999999018 999999019 999999020 999999021 999999022 999999023 999999024 999999025 999999026 999999027 999999028 999999029 99999...