結果

問題 No.3253 Banned Product
ユーザー tnakao0123
提出日時 2025-09-06 13:41:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 42,088 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-06 13:41:09
合計ジャッジ時間 884 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |   scanf("%d", &tn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3253.cc:  No.3253 Banned Product - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

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

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

    if (n > (ll)k * k) { printf("%d\n", n); continue; }
    
    int minn = max(2, n - 281);
    for (; n >= minn; n--) {
      bool ok = true;
      for (int p = 1; p <= k && p * p <= n; p++)
	if (n % p == 0) {
	  int q = n / p;
	  if (q <= k) { ok = false; break; }
	}

      if (ok) break;
    }

    printf("%d\n", (n >= minn) ? n : -1);
  }

  return 0;
}
0