結果
問題 | No.1146 土偶Ⅰ |
ユーザー |
![]() |
提出日時 | 2020-08-05 20:54:32 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 31,232 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-17 11:35:17 |
合計ジャッジ時間 | 1,167 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#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); }