Datasets:

ArXiv:
License:
File size: 1,420 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
public class Optimal{

  static int size = Integer.MAX_VALUE;
  static long gcd(long a, long b){
    if(b==0){
      return a;
    }
    return gcd(b, (a%b));
  }

  public static void main(String[] args) throws java.lang.Exception{

    Scanner sc = new Scanner(System.in);
    
   int t = sc.nextInt();
    while(t-->0){

      long n = sc.nextLong();
      long sum = 0;

      long a[] = new long [(int)n+1];
     for(long i=0; i<n;i++){
        a[(int)i] = sc.nextLong();

      }



      long pre[] = new long [(int)n+1];
      long suf[] = new long [(int)n+1];
      long h[] = new long [(int)n+1];
      for(long i=0; i<n; i++){
        sum+=a[(int)i];
      }

      if(a.length==1){
        System.out.println("1");
        continue;
      }
      
      pre[0] = a[0];
      for(long i=1; i<n; i++){
        pre[(int)i] = gcd(pre[(int)i-1],a[(int)i]);
      }

      // suffix
      suf[(int)n-1] = a[(int)n-1];
      for(long i = n-2; i>=0; i--){
        suf[(int)i] =gcd(suf[(int)i+1],a[(int)i]); 
      }

      h[0] = suf[1];
      h[(int)n-1] = pre[(int)n-2];

      for(long i=1;i<n-1;i++){
        h[(int)i] = gcd(pre[(int)i-1],suf[(int)i+1]);
      }

      
      long ans = Long.MAX_VALUE;
      long s = 0;

      for(long i = 0; i<n; i++){

        s  =((sum-a[(int)i])/h[(int)i])+1;
        ans = Math.min(ans,s);
        }
      System.out.println(ans);








    }
  }
}