結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 11 ms
6,944 KB
testcase_03 AC 13 ms
6,944 KB
testcase_04 AC 729 ms
6,940 KB
testcase_05 AC 1,115 ms
6,944 KB
testcase_06 AC 1,054 ms
6,944 KB
testcase_07 AC 1,068 ms
6,940 KB
testcase_08 AC 1,053 ms
6,940 KB
testcase_09 AC 624 ms
6,944 KB
testcase_10 AC 1,044 ms
6,944 KB
testcase_11 AC 1,008 ms
6,940 KB
testcase_12 AC 26 ms
6,940 KB
testcase_13 AC 871 ms
6,944 KB
testcase_14 AC 862 ms
6,944 KB
testcase_15 AC 614 ms
6,944 KB
testcase_16 AC 636 ms
6,940 KB
testcase_17 AC 617 ms
6,944 KB
testcase_18 AC 625 ms
6,944 KB
testcase_19 AC 638 ms
6,940 KB
testcase_20 AC 631 ms
6,940 KB
testcase_21 AC 623 ms
6,940 KB
testcase_22 AC 625 ms
6,940 KB
testcase_23 AC 623 ms
6,944 KB
testcase_24 AC 623 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>

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

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define MAX_LL (1LL<<62)

ll max(ll &a, ll &b) {if(a>b) return a; else return b;}
ll min(ll &a, ll &b) {if(a<b) return a; else return b;}

bool update_max(ll &a, const ll &b) {if(a<b){a=b; return true;} else return false;}
bool update_max(ld &a, const ld &b) {if(a<b){a=b; return true;} else return false;}
bool update_min(ll &a, const ll &b) {if(a>b){a=b; return true;} else return false;}
bool update_min(ld &a, const ld &b) {if(a>b){a=b; return true;} else return false;}

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