# ACM Learning Process-Guangdong University of Technology 2016 final-online race f I'm a good guy. 4 (number theory)

Source: Internet
Author: User

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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.