結果

問題 No.1146 土偶Ⅰ
ユーザー くれちーくれちー
提出日時 2020-08-05 20:54:32
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 31,328 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 13:39:59
合計ジャッジ時間 2,520 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2,bmi,bmi2")
#pragma GCC optimize("O3")

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

uint32_t gcd(uint32_t x, uint32_t y) {
  if (x == 0 || y == 0) {
    return x | y;
  }
  int x_tz = __builtin_ctz(x);
  int y_tz = __builtin_ctz(y);
  int k = x_tz < y_tz ? x_tz : y_tz;
  x >>= x_tz;
  y >>= y_tz;
  while (x != y) {
    if (x < y) {
      uint32_t t = x;
      x = y;
      y = t;
    }
    x -= y;
    x >>= __builtin_ctz(x);
  }
  return x << k;
}

int main(void) {
  size_t n;
  scanf("%zu", &n);
  uint32_t a[100];
  for (size_t i = 0; i < n; ++i) {
    scanf("%" SCNu32, &a[i]);
  }
  uint32_t cnt = 0;
  for (size_t i = 0; i < n; ++i) {
    for (size_t j = i + 1; j < n; ++j) {
      uint32_t d = gcd(a[i], a[j]);
      for (size_t k = j + 1; k < n; ++k) {
        if (gcd(d, a[k]) == 1) {
          ++cnt;
        }
      }
    }
  }
  printf("%" PRIu32 "\n", cnt);
}
0