結果
問題 | No.889 素数! |
ユーザー |
![]() |
提出日時 | 2019-09-20 21:38:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,179 bytes |
コンパイル時間 | 1,738 ms |
コンパイル使用メモリ | 173,996 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 16:52:26 |
合計ジャッジ時間 | 3,204 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 WA * 2 |
ソースコード
#include "bits/stdc++.h"using namespace std;using ll = long long;using pii = pair<int, int>;using pll = pair<ll, ll>;using vi = vector<int>;using vl = vector<ll>;using vvi = vector<vi>;using vvl = vector<vl>;const ll INF = 1LL << 60;const ll MOD = 1000000007;template <class T>bool chmax(T &a, const T &b) {return (a < b) ? (a = b, 1) : 0;}template <class T>bool chmin(T &a, const T &b) {return (b < a) ? (a = b, 1) : 0;}template <class C>void print(const C &c, std::ostream &os = std::cout) {std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));os << std::endl;}// Eratosthenes's sieve// create list of prime numbers in O(N)// check if the given number is prime in O(1)struct Sieve {vector<bool> isPrime;Sieve(size_t max) : isPrime(max + 1, true) {isPrime[0] = false;isPrime[1] = false;for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べるif (isPrime[i]) // iが素数ならばfor (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数はisPrime[i * j] = false; // 素数ではない}bool operator()(size_t n) { return isPrime[n]; }};// list up all factorstemplate <typename T>set<T> factors(T a) {set<T> facs;for (T i = 1; i * i <= a; ++i) {if (a % i == 0) {facs.insert(i);facs.insert(a / i);}}return facs;}int main() {int n;cin >> n;Sieve isprime(64);set<int> heiho;set<int> rippo;set<int> kanzen;for (int i = 2; i < 8; ++i) {heiho.insert(i*i);}for (int i = 0; i < 4; ++i) {rippo.insert(i*i*i);}kanzen.insert(6);kanzen.insert(28);if (isprime(n)) {cout << "Sosu!" << "\n";} else if (heiho.count(n) == 1) {cout << "Heihosu!" << "\n";} else if (rippo.count(n) == 1) {cout << "Ripposu!" << "\n";} else if (kanzen.count(n) == 1) {cout << "Kanzensu!" << "\n";} else {cout << n << "\n";}return 0;}