QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#867004#9738. Make It DivisiblesqrteipiWA 1ms3712kbC++201.2kb2025-01-22 23:59:122025-01-22 23:59:13

Judging History

你现在查看的是最新测评结果

  • [2025-01-22 23:59:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-22 23:59:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int factor[10000];
  int t;
  cin >> t;
  for (int j=0; j<t; j++){
    int n,k;
    cin >> n >> k;
    int q=1000000000;
    int arr[n];
    for (int i=0; i<n; i++){
      cin >> arr[i];
      q=min(q,arr[i]);
    }
    int g=0;
    for (int i=0; i<n; i++){
      if (arr[i]-q!=0){
        if (g==0){
          g=arr[i]-q;
        }else{
          g=gcd(arr[i]-q,g);
        }
      }
    }
    set<int> s;
    if (g==0){
      cout << k << " " << k*(k+1)/2 << endl;
    }else{
      s.insert(1);
      int pt=0;
      for (int i=2; i<=sqrt(g); i++){
        if (g%i==0){
          for (int p : s){
            factor[pt]=p, pt++;
          }
          for (int t=0; t<pt; t++){
            s.insert(factor[t]*i);
          }
          g/=i, pt=0;
        }
      }
      for (int p : s){
        factor[pt]=p, pt++;
      }
      for (int t=0; t<pt; t++){
        s.insert(factor[t]*g);
      }
      int ans=0, num=0;
      for (int p : s){
        if (q<p && p-q<=k){
          num++, ans+=p-q;
        }
      }
      cout << num << " " << ans << endl;
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

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: 3712kb

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'