QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#808823 | #9078. Greatest Common Divisor | rotcar07 | AC ✓ | 95ms | 3676kb | C++23 | 505b | 2024-12-11 07:25:53 | 2024-12-11 07:25:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int solve(){
int n,m,g=0;cin>>n>>m;
for(int i=2,x;i<=n;i++) cin>>x,g=gcd(g,x-m);
if(g==1) return -1;
if(!g) return (m==1);
int mn=INT_MAX;
auto chk=[&](int x){mn=min(mn,(x-m%x)%x);};
for(int i=2;i*i<=g;i++){
if(g%i==0)chk(i),chk(g/i);
}chk(g);
return mn;
}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T;cin>>T;
for(int _=1;_<=T;_++) cout<<"Case "<<_<<": "<<solve()<<'\n';
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3672kb
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: 95ms
memory: 3676kb
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