結果

問題 No.2589 Prepare Integers
ユーザー 👑 chro_96chro_96
提出日時 2023-12-17 19:34:42
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 29,952 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-17 19:34:44
合計ジャッジ時間 1,403 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long gcd (long long a, long long b) {
  if (b <= 0LL) {
    return a;
  }
  return gcd(b, a%b);
}

int main () {
  long long k = 0LL;
  int q = 0;
  int t = 0;
  long long x = 0LL;
  
  int res = 0;
  
  int cnt = 0;
  long long g[64] = {};
  int len = 0;
  
  res = scanf("%lld", &k);
  res = scanf("%d", &q);
  while (q > 0) {
    res = scanf("%d", &t);
    res = scanf("%lld", &x);
    if (t == 1) {
      int tmplen = 0;
      long long tmp = x;
      while (tmp > 0LL) {
        g[tmplen] = gcd(g[tmplen], tmp%k);
        tmp /= k;
        tmplen++;
      }
      if (tmplen > len) {
        len = tmplen;
      }
      cnt++;
    } else if (t == 2 && cnt < 1 && x > 1LL) {
      printf("-1\n");
    } else if (t == 2 && cnt < 1) {
      printf("0\n");
    } else if (t == 2 && cnt < 2) {
      long long g_all = k;
      for (int i = 0; i < len; i++) {
        g_all = gcd(g_all, g[i]);
      }
      if (k/g_all < x) {
        printf("-1\n");
      } else {
        long long ans = 0LL;
        printf("%lld\n", ans);
      }
    }
    q--;
  }
  
  return 0;
}
0