結果

問題 No.2016 Countdown Divisors
ユーザー tnakao0123tnakao0123
提出日時 2022-07-23 15:58:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,248 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 51,468 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-18 14:16:34
合計ジャッジ時間 4,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2016.cc:  No.2016 Countdown Divisors - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_P = 32000;

/* typedef */

typedef vector<int> vi;

/* global variables */

bool primes[MAX_P + 1];

/* subroutines */

int gen_primes(int maxp, vi &pnums) {
  fill(primes, primes + maxp + 1, true);
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
  return (int)pnums.size();
}

int divnum(int n, vi &pnums) {
  int d = 1;
  int pn = pnums.size();
  for (int i = 0; i < pn; i++) {
    int pi = pnums[i];
    if (pi * pi > n) {
      if (n > 1) d *= 2;
      break;
    }

    if (n % pi == 0) {
      int fi = 0;
      while (n % pi == 0) n /= pi, fi++;
      d *= fi + 1;
    }
  }
  return d;
}

/* subroutines */

/* main */

int main() {
  vi pnums;
  gen_primes(MAX_P, pnums);

  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d", &n);

    while (n > 2) n -= divnum(n, pnums);
    printf("%d\n", n);
  }
  return 0;
}
0