結果

問題 No.1146 土偶Ⅰ
ユーザー くれちー
提出日時 2020-08-05 20:54:32
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 918 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 313 ms
コンパイル使用メモリ 39,552 KB
最終ジャッジ日時 2026-02-22 06:02:29
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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