QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795435 | #9738. Make It Divisible | Nlll# | WA | 0ms | 3720kb | C++20 | 1.2kb | 2024-11-30 20:28:09 | 2024-11-30 20:28:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>-k;--i)
const int N = 5e4+111;
int a[N],b[N];
int gcd(int x,int y)
{
if(!x) return y;
if(!y) return x;
while(y)
{
int t=x%y;
x=y;
y=t;
}
return x;
}
void sol(){
int n,k;
cin>>n>>k;
FOR(i,1,n) cin>>a[i];
sort(a+1,a+1+n);
FOR(i,1,n) b[i] = a[i]-a[1];
int d = 0;
FOR(i,1,n) d = gcd(d,b[i]);
if(d==0)
{
cout<<k<<' '<<1ll*k*(k+1)/2<<'\n';
return;
}
long long sum = 0;
long long tot = 0;
for(int i=1;i*i<=d;i++)
{
if(d%i==0){
if(i>a[1]&&(i-a[1])<=k){
sum += i-a[1];
++tot;
}
if(d!=i*i){
if(d/i>a[1]&&(d/i-a[1])<=k){
sum += d/i-a[1];
++tot;
}
}
}
}
cout<<tot<<' '<<sum<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
sol();
}
return 0;
}
/*
1
2 100
2 20
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'