QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#947101 | #9078. Greatest Common Divisor | xjt05# | AC ✓ | 160ms | 9044kb | C++23 | 3.1kb | 2025-03-22 14:00:06 | 2025-03-22 14:00:07 |
Judging History
answer
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll long long
#define lowbit(x) (x & -x)
#define endl "\n"// 交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{
ll ans = 1;
x %= mod;
while (y)
{
if (y & 1)
{
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans;
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
inline ll read()
{
register ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c>'9')
{
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速
c = getchar();
}
return x * f;
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
// struct s
// {
// ll l,r;
// friend bool operator<(cosnt s &a, const s& b)
// {
// return
// };
// };
int main()
{
fio();
ll t;
cin >> t;
ll cs=0;
while (t--)
{
cs++;
ll n;
cin>>n;
vector<ll>a(n+5);set<ll>k;
ll d;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
k.insert(a[i]);
}
cout<<"Case"<<" "<<cs<<": ";
if(k.size()==1)
{
ll ans=0;
if((*k.begin())==1)ans++;
cout<<ans<<endl;
}
else
{
ll f=-1;
ll z=0;
for(auto j:k)
{
if(f==-1)f=j;
else
{
z=gcd(z,j-f);
f=j;
}
}
if(z==1)cout<<-1<<endl;
else
{
d=*k.begin();
ll ans=1e18;
if(d%z==0)ans=0;
else ans=(d/z+1)*z-d;
for(ll i=2;i*i<=z;i++)
{
if(z%i==0)
{
ll x=z/i;
if(d%i==0||d%x==0)ans=0;
else
{
ans=min({ans,(d/i+1)*i-d,(d/x+1)*x-d});
}
}
}
cout<<ans<<endl;
}
}
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
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: 160ms
memory: 9044kb
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