結果

問題 No.847 Divisors of Power
ユーザー akakimidoriakakimidori
提出日時 2019-07-05 21:44:34
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 07:11:09
合計ジャッジ時間 1,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

i32 calc (i64 n, i64 m, i64 *p, i64 *a, i32 len) {
  if (n > m) return 0;
  i32 ans = 1;
  for (i32 i = 0; i < len; ++i) {
    i64 t = n * p[i];
    i64 j = 1;
    while (t <= m && j <= a[i]) {
      ans += calc (t, m, p + i + 1, a + i + 1, len - i - 1);
      t *= p[i];
      j++;
    }
  }
  return ans;
}

void run (void) {
  i64 n, k, m;  
  scanf ("%" SCNi64 "%" SCNi64 "%" SCNi64, &n, &k, &m);
  i64 p[32], a[32];
  i32 len = 0;
  for (i32 i = 2; i * i <= n; ++i) {
    if (n % i != 0) continue;
    p[len] = i;
    a[len] = 0;
    while (n % i == 0) {
      a[len]++;
      n /= i;
    }
    len++;
  }
  if (n > 1) {
    p[len] = n;
    a[len++] = 1;
  }
  for (i32 i = 0; i < len; ++i) {
    a[i] *= k;
  }
  i32 ans = calc (1, m, p, a, len);
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}
0