結果

問題 No.2682 Visible Divisible
ユーザー ぷらぷら
提出日時 2024-03-20 21:10:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 138,668 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-20 21:11:01
合計ジャッジ時間 7,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 343 ms
6,548 KB
testcase_01 AC 531 ms
6,548 KB
testcase_02 AC 451 ms
6,548 KB
testcase_03 AC 453 ms
6,548 KB
testcase_04 AC 152 ms
6,548 KB
testcase_05 AC 179 ms
6,548 KB
testcase_06 AC 211 ms
6,548 KB
testcase_07 AC 135 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 382 ms
6,548 KB
testcase_12 AC 313 ms
6,548 KB
testcase_13 AC 217 ms
6,548 KB
testcase_14 AC 547 ms
6,548 KB
testcase_15 AC 372 ms
6,548 KB
testcase_16 AC 307 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

long long binary_gcd(long long a,long long b) {
    if(a == 0 || b == 0) return a+b;
    int k = 0;
    while(!((a&1)|(b&1))) {
        k++;
        a >>= 1;
        b >>= 1;
    }
    while (a != b) {
        while(!(a&1)) a >>= 1;
        while(!(b&1)) b >>= 1;
        if(a > b) a -= b;
        else if(a < b) b -= a;
    }
    return a << k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long K;
    cin >> N >> K;
    vector<long long>X(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i];
    }
    while(K > 1)  {
        long long g = -1;
        for(int i = 0; i < N; i++) {
            if(binary_gcd(K,X[i]) != 1) {
                g = binary_gcd(K,X[i]);
                break;
            }
        }
        if(g == -1) {
            break;
        }
        K /= g;
        for(int i = 0; i < N; i++) {
            X[i] /= binary_gcd(g,X[i]);
        }
    }
    cout << ((K == 1)?"Yes":"No") << "\n";
}
0