题意:给你n个数,你可以对于数组中任意的两个数x,y进行以下操作:
如果x>y并且x-y不在数组中那么将x-y加入到数组中。
问你经过任意次操作,可以得到的最大的数组长度为多少?
思路:
两个数不断相减,本质就是不断取模,(剩下的数就是大的数除以小的数的余数)参考更相减损术求最大公约数的原理。因此,如果没法继续减损,也就是说一直减损到两个数相等,这个数就是最大公约数。那么对于n个数的最大公约数,直接用最大值/最大公约数便是我们要得到的结果。
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;
const int N=1000000+100;
int n ,m,h;
int s[N];
int main()
{
int t;
cin>>t;
for(int i =1;i<=t;i++)
{
cin>>n;
int k=0;
for(int j=1;j<=n;j++)
{
cin>>s[j];
if(!k)k=s[j];
else k=__gcd(k,s[j]);
}
cout<<s[n]/k<<endl;
}
return 0;
}