QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789143#5542. Doubled GCDFireball0424#WA 0ms3744kbC++141.4kb2024-11-27 19:24:222024-11-27 19:24:23

Judging History

你现在查看的是最新测评结果

  • [2024-11-27 19:24:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3744kb
  • [2024-11-27 19:24:22]
  • 提交

answer

// #pragma GCC optimizer("Ofast")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
//#define int long long 
#define ld long double
#define ull unsigned long long 
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
//#define sz(x) (int)x.size()
using namespace std;

#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif 

void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    return gcd(b, a % b);
}

signed main(){
    tofu;
    int n;
    cin >> n;

    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];

    int g = a[0];
    for(int i = 1; i < n; ++i) g = gcd(g, a[i]);
    while(g % 2 == 0) g /= 2;
    
    priority_queue<int, vector<int>, greater<int> > q;
    for(int i = 0; i < n; ++i){
        int x = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            ++x;
        }
        q.push(x);
    }

    while(q.size() > 1){
        int x = q.top();
        q.pop();
        int y = q.top();
        q.pop();

        q.push(min(x, y) + 1);
    }

    int ans = 1;
    int x = q.top();
    while(x--) ans = (ans * 2);
    db(ans * g);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

3
2 4 6

output:

8 

result:

ok single line: '8 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

3
3 5 7

output:

2 

result:

ok single line: '2 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

4
9 9 9 9

output:

36 

result:

ok single line: '36 '

Test #4:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

5
10 100 1000 10000 100000

output:

160 

result:

ok single line: '160 '

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3528kb

input:

8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

output:

-589934592 

result:

wrong answer 1st lines differ - expected: '8000000000', found: '-589934592 '