이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define allarr(a) a, a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<int, pi> trp;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
ll _abs(ll x) { return (x > 0 ? x : -x); }
vector<int> ans;
set <pi> dp ;
int N;
map<int,vector<int>> divisors ;
void solve(int n, int x)
{
// cout << n << " " << x << endl;
if (x >= N)return ;
if (dp.find({n,x})!=dp.end())
return;
dp.insert({n,x});
if (n == 1)
{
ans.pb(x);
return;
}
for( int d : divisors[n] ){
solve ( d , x + n / d - 1 ) ;
}
}
set<int> visited ;
void gen(int n ){
// cerr << n << endl;
if( visited.count(n) )return ;
if( n == 1 )return ;
for(int i = 1 ; i * i <= n ; i++ ){
if( n % i == 0 ){
divisors[n].pb(i) ;
if( i != 1 ){
divisors[n].pb(n/i) ;
gen( n / i ) ;
}
gen( i ) ;
}
}
}
int main()
{
cin >> N;
gen(N) ;
solve(N, 0);
cout << ans.size() << endl;
sort(all(ans));
for (int i : ans)
cout << i << " ";
}
# | 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... |