結果

問題 No.2751 429-like Number
ユーザー Y.Y.Y.Y.
提出日時 2024-05-09 03:51:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,100 ms / 4,000 ms
コード長 1,047 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 100,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-10 18:23:18
合計ジャッジ時間 18,798 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 11 ms
6,944 KB
testcase_02 AC 10 ms
6,940 KB
testcase_03 AC 11 ms
6,944 KB
testcase_04 AC 715 ms
6,940 KB
testcase_05 AC 1,089 ms
6,944 KB
testcase_06 AC 1,083 ms
6,940 KB
testcase_07 AC 1,100 ms
6,940 KB
testcase_08 AC 1,082 ms
6,940 KB
testcase_09 AC 650 ms
6,940 KB
testcase_10 AC 1,078 ms
6,940 KB
testcase_11 AC 1,058 ms
6,940 KB
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 888 ms
6,940 KB
testcase_14 AC 894 ms
6,944 KB
testcase_15 AC 650 ms
6,944 KB
testcase_16 AC 655 ms
6,940 KB
testcase_17 AC 648 ms
6,940 KB
testcase_18 AC 653 ms
6,944 KB
testcase_19 AC 656 ms
6,940 KB
testcase_20 AC 652 ms
6,940 KB
testcase_21 AC 656 ms
6,940 KB
testcase_22 AC 646 ms
6,944 KB
testcase_23 AC 638 ms
6,944 KB
testcase_24 AC 638 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;
typedef string str;

vector<ll> calc_primes(const ll max_num) {
  if(max_num < 2) return {};
  vector<ll> data = {2};
  for(ll num = 3; num <= max_num; num += 2){
    for(ll p : data){
      if(num % p == 0) break;
      else if (p * p > num){
        data.push_back(num);
        break;
      }
    }
  }
  return data;
}

int main() {
  ll Q;
  cin >> Q;

  vector<ll> A(Q);
  for(ll i=0; i<Q; i++){
    cin >> A[i];
  }
  const ll N_MAX = 10000000000;
  vector<ll> primes = calc_primes(pow(N_MAX, 0.5));

  ll counter = 0;
  ll num;
  
  for(ll j=0; j<Q; j++){
    counter = 0;
    num = A[j];
    
    for(ll i=0; i < primes.size(); i++){
      while(num % primes[i] == 0){
        num /= primes[i];
        counter++;
        if(counter > 3)
          goto label_break;
      }
    }
    if(num != 1)
      counter++;

    label_break:
    if(counter == 3)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  
  return 0;
}
0