Title Link:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=5
This topic is a question of number theory, should consider the use of the principle of tolerance, here to the LCM .
But straight up is T, considering the simultaneous existence of I and ki in the sequence , in fact I only need to consider i, So the pairs that are multiples in the sequence are processed first.
The hqw is used to the wording of the house.
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<vector>#include<string>#defineLL Long Longusing namespacestd;ConstLL MAXN =1e9;intN;intt[ -], a[ -], Len; LL ans;voidinput () {scanf ("%d", &N); Len=N; for(inti =0; i < Len; ++i) scanf ("%d", &T[i]); for(inti =0; i < Len; ++i) {if(T[i] = =-1)Continue; for(intj =0; J < Len; ++j) {if(i = = j)Continue; if(T[j] = =-1)Continue; if(T[j]%t[i] = =0) T[j] =-1; } } inttop =0; for(inti =0; i < Len; ++i)if(T[i]! =-1) A[top++] =T[i]; Len=top; Sort (A, a+len);} ll GCD (ll X, ll y) {ll r; while(Y! =0) {R=y; Y= x percenty; X=R; } returnx;} ll LCM (ll X, ll y) {returnX/GCD (x, y) *y;}voidDfsintNow, LL num,intSZ) { if(now = =Len) { if(SZ) {LL last= maxn/num; if(sz&1) ans-=Last ; ElseAns + =Last ; } return; } if(Num%a[now] = =0)return; DFS ( now+1, num, SZ); LL T=LCM (num, a[now]); if(t <= maxn) DFS (now+1, T, sz+1);}voidWork () {if(len = =1&& a[0] ==1) printf ("0\n"); Else{ans=MAXN; DFS (0,1,0); cout<< ans <<Endl; }}intMain () {//freopen ("test.in", "R", stdin); intT; scanf ("%d", &T); for(intTimes =1; Times <= T; ++Times ) {input (); Work (); } return 0;}
View Code
ACM Learning Process-Guangdong University of Technology 2016 final-online race f I'm a good guy. 4 (number theory)