QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#953605 | #9078. Greatest Common Divisor | Kaze_ | AC ✓ | 105ms | 4480kb | C++23 | 1.5kb | 2025-03-27 21:33:31 | 2025-03-27 21:33:32 |
Judging History
answer
// It's a wonderful life.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define DEBUG 1
const ll N = 2000000;
const ll MOD = 998244353;
const ll MAX = 1e18;
ll n,a[N];
bool check(ll x){
if (x <= 1){
return 0;
}
for (ll i = 2;i*i<=x;i++){
if (x % i == 0){
return 0;
}
}
return 1;
}
void solve(int idx){
cin >> n;
for (int i = 1;i<n+1;i++){
cin >> a[i];
}
sort(a + 1,a + 1 + n);
ll x = 0;
for (int i = 2;i<n+1;i++){
x = __gcd(x,a[i] - a[i-1]);
}
if (x == 0){
if (a[1] == 1){
cout << "Case " << idx << ": " << 1 << endl;
}else{
cout << "Case " << idx << ": " << 0 << endl;
}
return;
}
vector<ll> q;
for (ll i = 2;i*i<=x;i++){
if (x % i == 0) q.push_back(i);
while (x % i == 0) x /= i;
}
if (x > 1){
q.push_back(x);
}
ll ans = MAX;
for (auto v : q){
ll res = 0;
res = v - a[1] % v;
res %= v;
ans = min(ans,res);
}
if (ans == MAX){
ans = -1;
}
cout << "Case " << idx << ": " << ans << endl;
// cout << ans << endl;
return;
}
signed main(){
// freopen("input.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _ = 1;
cin >> _;
for (int i = 1;i<_+1;i++){
solve(i);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
3 1 2 5 2 5 9 5 7 5 3 5 7 9 11
output:
Case 1: 0 Case 2: -1 Case 3: 1
result:
ok 9 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 1 1 3 1 1 1 3 2 2 2 3 1 2 3 3 1 3 5 3 1 10 19
output:
Case 1: 1 Case 2: 1 Case 3: 0 Case 4: -1 Case 5: 1 Case 6: 2
result:
ok 18 tokens
Test #3:
score: 0
Accepted
time: 105ms
memory: 4480kb
input:
100 1 1 1 2 5 879961169 879961169 879961169 879961169 152615033 8 876139349 292671665 876139349 876139349 876139349 876139349 876139349 876139349 10 825359939 825359939 825359939 825359939 825359939 825359939 594330487 825359939 825359939 825359939 5 985688421 985688421 718069623 985688421 985688421...
output:
Case 1: 1 Case 2: 0 Case 3: 1 Case 4: 1 Case 5: 1 Case 6: 0 Case 7: 1 Case 8: -1 Case 9: -1 Case 10: 0 Case 11: 0 Case 12: 0 Case 13: 1 Case 14: 0 Case 15: 45 Case 16: 11 Case 17: 1 Case 18: -1 Case 19: -1 Case 20: 855585752 Case 21: 1982 Case 22: 260 Case 23: 0 Case 24: 0 Case 25: 0 Case 26: 0 Case...
result:
ok 300 tokens
Extra Test:
score: 0
Extra Test Passed