結果
| 問題 |
No.2795 Perfect Number
|
| コンテスト | |
| ユーザー |
Misuki
|
| 提出日時 | 2024-06-28 21:31:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,751 bytes |
| コンパイル時間 | 2,486 ms |
| コンパイル使用メモリ | 207,436 KB |
| 実行使用メモリ | 12,256 KB |
| 最終ジャッジ日時 | 2024-06-28 21:31:18 |
| 合計ジャッジ時間 | 3,519 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 WA * 4 |
ソースコード
#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
#include <bit>
#include <compare>
#include <concepts>
#include <numbers>
#include <ranges>
#include <span>
#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)
#define clock chrono::steady_clock::now().time_since_epoch().count()
#ifdef DEBUG
#define dbg(x) cout << (#x) << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
//#define double ldb
template<ranges::forward_range rng, class T = ranges::range_value_t<rng>, class OP = plus<T>>
void pSum(rng &&v) {
if (!v.empty())
for(T p = v[0]; T &x : v | views::drop(1))
x = p = OP()(p, x);
}
template<ranges::forward_range rng, class T = ranges::range_value_t<rng>, class OP>
void pSum(rng &&v, OP op) {
if (!v.empty())
for(T p = v[0]; T &x : v | views::drop(1))
x = p = op(p, x);
}
template<class T>
T floorDiv(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a - b + 1) / b;
}
template<class T>
T ceilDiv(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? (a + b - 1) / b : a / b;
}
template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
for(const T &X : arr)
os << X << ' ';
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
for(const T &X : vec)
os << X << ' ';
return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T> &s) {
for(const T &x : s)
os << x << ' ';
return os;
}
const int C = 1000001;
vector<int> prime;
int mpf[C];
void sieve() {
for(int i = 1; i < C; i++)
mpf[i] = i;
for(int i = 2; i < C; i++) {
if (mpf[i] == i)
prime.emplace_back(i);
for(int P : prime) {
if (P > mpf[i] or i * P >= C)
break;
mpf[i * P] = P;
}
}
}
vector<pii> factorize(int val) {
vector<pii> res;
while(val > 1) {
int p = mpf[val];
res.emplace_back(p, 0);
while(val % p == 0)
res.back().second += 1, val /= p;
}
return res;
}
vector<int> factors(int val) {
vector<int> res(1, 1);
for(auto [p, idx] : factorize(val)) {
vector<int> tmp;
for(int i = 0, base = 1; i <= idx; i++, base *= p)
for(int X : res)
tmp.emplace_back(X * base);
res.swap(tmp);
}
return res;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(NULL);
sieve();
vector<int> sol;
for(int i = 0, s = 1; s * s * 2 <= (1ll << 60); i++, s *= 2) {
if (mpf[i + 1] == (i + 1)) sol.emplace_back(s * (2 * s - 1));
}
int n; cin >> n;
if (ranges::find(sol, n) != sol.end()) cout << "Yes\n";
else cout << "No\n";
return 0;
}
Misuki