QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#826919 | #9078. Greatest Common Divisor | abovecloud | AC ✓ | 123ms | 4388kb | C++23 | 1.7kb | 2024-12-22 17:12:35 | 2024-12-22 17:12:35 |
Judging History
answer
/*** WORK : 省赛\桂林ccpc\G.cpp ***/
/*** TIME : 2024/12/22 16:41 ***/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define se second
#define fi first
#define endl '\n'
using vi = vector<int>;using vvi = vector<vi>;using vvvi = vector<vvi>;
using pii = pair<int,int>;using vpii = vector<pii>;using vvpii = vector<vpii>;
using mii = map<int,int>;using mpi = map<pii,int>;using si = set<int>;
istream& operator>>(istream& in,vi& a){for(int &x:a)in>>x;return in;}
ostream& operator<<(ostream& out,const vi& a){for(int x:a)out<<x<<" ";return out;}
const int INF = LLONG_MAX/4;const int MOD = (int)1e9 + 7;
const int MAXN = 2e5 + 5;
int cnt = 0;
void solve()
{
int n,t;cin >> n;
vi a(n);
cin >> a;
sort(all(a));
a.resize(unique(all(a))-a.begin());
n = a.size();
cout << "Case " << ++cnt << ": ";
if(n==1){
if(a[0]==1)cout << 1 << endl;
else cout << 0 << endl;
return;
}
int g = 0;
for(int i=1;i<n;i++){
g = __gcd(g,a[i]-a[i-1]);
}
// cout << g << endl;
if(g==1){
cout << -1 << endl;
}else{
int ans = INF;
for(int i=2;i*i<=g;i++){
if(g%i)continue;
ans = min(ans,(i - a[0]%i)%i);
ans = min(ans,(g/i - a[0]%(g/i))%(g/i));
}
ans = min(ans,(g - a[0]%g)%g);
cout << ans << endl;
}
// cout << __gcd(a[0],a[1]);
}
int32_t main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(12);
int T = 1;
cin >> T;
while (T--)
solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
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: 3616kb
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: 123ms
memory: 4388kb
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