给你 n (2 <= n <= 60,000) 个球,每球上都写有互不相同的数字t ( 0 <= t < 100,000),这些球放在一个盒子里.开始你能执行一种加球操作:选择任意两个球: x 和y,然后看| x - y |在已经有的球中是否存在,如果不存在,就把|x - y|写在一个球上,把这个球加入这个盒子,这里就成功完成了一次加球操作. 你就一直加球,直到盒子中任意两个数的差,在集合中已经存在
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<stack> #include<map> #include<set> #include<vector> #include<queue> #include<string> #include<cmath> using namespace std; #define ll long long #define rep(i,n) for(int i =0; i < n; ++i) #define CLR(x) memset(x,0,sizeof x) #define MEM(a,b) memset(a,b,sizeof a) #define pr(x) cout << #x << " = " << x << " "; #define prln(x) cout << #x << " = " << x << endl; const int maxn = 4e5+100; const int INF = 0x3f3f3f3f; int a[maxn]; int main(){ #ifdef LOCAL freopen("/home/zeroxf/桌面/in.txt","r",stdin); //freopen("/home/zeroxf/桌面/out.txt","w",stdout); #endif int t,n; scanf("%d", &t); while(t--){ scanf("%d", &n); double ans = 0; int b = 0, x; for(int i = 0; i < n; ++i){ scanf("%d", &a[i]); if(a[i] > b) b = a[i]; } x = b; bool ok = true; for(int i = 0; i < n; ++i){ if(a[i] == 0) { ok = false; continue; } x = __gcd(x, a[i]); } int num = b/x; if(!ok) num++; ans = num-n; for(int i = 1; i <= num; ++i){ ans = ans +num*1.0/i; } int temp = ans; printf("%d\n",temp); } return 0; }