結果
問題 | No.36 素数が嫌い! |
ユーザー |
|
提出日時 | 2015-05-13 13:31:54 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 1,912 bytes |
コンパイル時間 | 791 ms |
コンパイル使用メモリ | 90,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 00:18:22 |
合計ジャッジ時間 | 2,069 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector<int> VI; typedef pair<int, int> PI; const double EPS=1e-9; class Power { typedef long long i64; public: /* a^b with no modulo operations */ static long long power(long long a, long long b) { i64 s = 1; i64 c = a; while (b > 0) { if (b % 2) { s *= c; } c *= c; b /= 2; } return s; } /* return (a,b) s.t, n = a^b and b is maximal. O(64) */ static pair<long long, int> toPower(long long n) { for (int i = 64; i >= 2; i--) { i64 app = pow(n, 1.0/i); for (int d = -4; d <= 4; d++) { i64 x = app + d; if (x <= 0) continue; if (power(x, i) == n) { return pair<i64, int>(x, i); } } } return pair<i64, int>(n, 1); } /* factorize n and returns prime factors and their exponents. O(sqrt(n)) */ static vector<pair<long long, int> > factorize(long long n) { vector<pair<i64, int> > res; i64 p = 2; int c = 0; while (n >= 1) { if (c == 0 && n < p * p) { if(n != 1) { res.push_back(pair<i64, int>(n,1)); } break; } if (n % p != 0) { if (c > 0) { res.push_back(pair<i64, int>(p,c)); } p++; c = 0; continue; } n /= p; c++; } return res; } }; int main(void){ ll n; cin >> n; vector<pair<ll, int> > res = Power::factorize(n); int t = 0; REP(i, 0, res.size()) { t += res[i].second; } cout << (t >= 3 ? "YES" : "NO") << endl; }