結果
| 問題 |
No.36 素数が嫌い!
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2015-09-26 14:41:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 5,000 ms |
| コード長 | 1,809 bytes |
| コンパイル時間 | 838 ms |
| コンパイル使用メモリ | 94,384 KB |
| 実行使用メモリ | 8,808 KB |
| 最終ジャッジ日時 | 2024-06-27 00:30:45 |
| 合計ジャッジ時間 | 2,713 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
vector<bool> isprime;
vector<int> primes;
void sieve(int n){
if((int)isprime.size() >= n+1) return;
isprime.assign(n+1, true);
isprime[0] = isprime[1] = false;
int sqrtn = (int)(sqrt(n * 1.) + .5);
for(int i = 2; i <= sqrtn; i ++) if(isprime[i]) {
for(int j = i * i; j <= n; j += i)
isprime[j] = false;
}
primes.clear();
for(int i = 2; i <= n; i ++) if(isprime[i])
primes.push_back(i);
}
typedef long long FactorsInt;
typedef vector<pair<FactorsInt,int> > Factors;
void primeFactors(FactorsInt x, Factors &out_v) {
out_v.clear();
int sqrtx = (int)(sqrt(x*1.) + 10.5);
sieve(sqrtx);
for(vector<int>::const_iterator p = primes.begin(); p != primes.end(); ++ p) {
if(*p > sqrtx) break;
if(x % *p == 0) {
int t = 1;
x /= *p;
while(x % *p == 0) {
t ++;
x /= *p;
}
out_v.push_back(make_pair(*p, t));
}
}
if(x != 1) out_v.push_back(make_pair(x, 1));
}
int main() {
long long N;
while(~scanf("%lld", &N)) {
Factors fs;
primeFactors(N, fs);
int cnt = 0;
for(auto it = fs.begin(); it != fs.end(); ++ it)
cnt += it->second;
bool ans = cnt >= 3;
puts(ans ? "YES" : "NO");
}
return 0;
}
anta