이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
// #define int long long
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pb push_back
/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/
const long double PI = 3.1415926535897932384626433832795;
const int INF = 1000000000000000000;
const int MOD = 1000000007;
const int MOD2 = 1000000009;
const long double EPS = 1e-6;
using namespace std;
int n;
map<int, vector<int>> mp;
map<pii, bool> flag;
vector<int> v;
void solve(int x, int sum) {
if (flag[{x, sum}]) return;
flag[{x, sum}] = 1;
v.push_back(sum + x - 1);
if (mp.find(x) != mp.end()) {
for (auto i : mp[x]) solve(i, sum + x / i - 1);
}
else {
for (int i = 2; i * i <= x; i++) if (x % i == 0) {
if (i * i == x) {
mp[x].push_back(i);
solve(i, sum + i - 1);
}
else {
mp[x].push_back(i);
mp[x].push_back(x / i);
solve(i, sum + x / i - 1);
solve(x / i, sum + i - 1);
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// freopen("cf.inp", "r", stdin);
// freopen("cf.out", "w", stdout);
cin >> n;
solve(n, 0);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
cout << sz(v) << "\n";
for (auto x : v) cout << x << " ";
}
컴파일 시 표준 에러 (stderr) 메시지
toy.cpp:21:17: warning: overflow in conversion from 'long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
21 | const int INF = 1000000000000000000;
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |