結果

問題 No.136 Yet Another GCD Problem
ユーザー らっしー(raccy)
提出日時 2015-01-26 00:23:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 808 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 65,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 03:07:14
合計ジャッジ時間 1,746 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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

std::vector<int> prime_list(int max) {
  std::vector<int> list(max + 1);
  int i = -1;
  for (auto &x: list)
    x = ++i;
  list[0] = 0;
  list[1] = 0;
  for (i = 2; i <= max; ++i)
    if (list[i] != 0)
      for (int j = 2; j <= max / i; ++j)
        list[i * j] = 0;
  std::sort(list.begin(), list.end());
  auto result = std::unique(list.begin(), list.end());
  return std::vector<int>(list.begin() + 1, result);
}

int main() {
  std::vector<int> prime;

  int n, k;
  std::cin >> n >> k;

  // for(int prime: prime_list(n / 2))
  //   std::cout << prime << " ";

  for(int prime: prime_list(n / 2)) {
    if (n % prime == 0) {
      std::cout << (n / prime) << std::endl;
      return 0;
    }
  }
  std::cout << 1 << std::endl;
  return 0;
}
0