結果

問題 No.36 素数が嫌い!
ユーザー alpha_virginis
提出日時 2015-03-11 01:03:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 1,309 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 70,340 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-27 00:16:28
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <math.h>

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>



int main() {

  /* default begin */
  long i, j, k;
  long n, m;
  long temp;
  long t;
  std::vector<long> v;
  bool b;
  /* default end */

  long N;
  long count = 0;

  std::cin >> N;

  if( N <= 7 ) {
    std::cout << "NO" << std::endl;
    return 0;
  }
  
  b = false;

  t = (long)sqrt((double)N)+1;

  i = 2;
  if( (N & 0x03) == 0 ) {
    b = true;
    goto label_1;
  }
  else {
    if( (N & 0x01) == 0 ) {
      count++;
      N >>= 1;
    }
  }

  i = 3;
  while( (N % i) == 0 ) {
    if( count >= 2 ) {
      b = true;
      goto label_1;
    }
    count++;
    N /= i;
    t = (long)sqrt((double)N)+1; 
  }
  
  for(i = 5; i <= t;) {
    while( (N % i) == 0 ) {
      if( count >= 2 ) {
	b = true;
	goto label_1;
      }
      count++;
      N /= i;
      t = (long)sqrt((double)N)+1; 
    }
    i += 2;
    while( (N % i) == 0 ) {
      if( count >= 2 ) {
	b = true;
	goto label_1;
      }
      count++;
      N /= i;
      t = (long)sqrt((double)N)+1; 
    }
    i += 4;
  }

  if( N != 1 ) {
    if( count >= 2 ) {
      b = true;
    }
  }
  
 label_1:
  
  if( b ) {
    std::cout << "YES" << std::endl;
  }
  else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}

0