Halloween tickets.

Source: Internet
Author: User

Halloween tickets.

[Halloween party before the start ...]

Halloween arrived, Lazyjazz to run a big party (communistParty)!

So Lazyjazz invited classmates friends, near relatives total n people, each sent a party ticket.

But the day of Halloween, somehow came  n+ 1   Individual ( sure is a ghost festival ), and everyone took a ticket, which makes lazyjazz very headache.

Fortunately, when the ticket was issued, each coupon printed a verification code. The verification code of the real ticket is obtained by a fixed composite x by a different prime number p I on the last 22 tickets .

So Lazyjazz one by one examined the verification code of all, and found an alternative (that is, the quotient of the X is not satisfied with a prime number), so the security of the good student terrorists dragged out.

Lazyjazz thought it was very interesting and decided to tell you all the verification codes he saw and let you guess which verification code was fake.

Input format

The first line, a positive integer n (9<n), indicates the normal number of people to be

The second line containsn+1  A positive integer separated by a space  ai, indicating the actual presence of  < Span class= "Mathjax_preview" >n+1  in the personal hands of the ticket on the verification code.

Input data guarantees only one "alternative" verification code, and can be judged

Output format

A positive integer that represents the fake verification code.

Sample input
1012 76 92 116 87 44 8 20 68 28 52
Output
87
国庆Day3的T1
一如既往地沙雕,被卡了int
最重要的是这次还要记成绩
慌得一批
首先是一个素数筛(打表会被卡)
然后我们可以知道,枚举那个合数,但是全都判的话是O(nx)的,是会T的
所以我们来推一个规律,因为只有一个是不符合的,所以选三个数的话,就可以保证至少有两个合法的,所以我们就可以用O(3x)的时间得到x
然后就可以写一个O(n)来判断
下面给出代码:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>using namespaceStd;inlineLong LongRd () {Long Longx=0, f=1; CharCh=GetChar ();  for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1;  for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; returnx*F;} InlinevoidWriteLong Longx) {    if(x<0) Putchar ('-'), x=-x; if(x>9) Write (x/Ten); Putchar (x%Ten+'0'); return ;}intbook[15000006];intpr[1500006];intTotal=0; inlinevoidPreLong Longx) {     for(intI=2; i<=x;i++){        if(book[i]==0) {Book[i]=i; pr[++total]=i; }         for(intj=1; j<=total;j++){            if(pr[j]>book[i]| | PR[J]*I&GT;X) Break; Book[i*pr[j]]=Pr[j]; }} memset (book,1,sizeof(book));  for(intI=1; i<=total;i++) book[pr[i]]=0; return ;}intN;Long Longa[100006];intMain () {Pre (1500000); scanf ("%d",&N);  for(intI=1; i<=n+1; i++) a[i]=Rd (); int Set=0;  for(intI=4; i<=100000; i++){        if(book[i]==0)Continue; intCnt=0; if(a[1]/i<1500000&&a[1]%i==0&&book[a[1]/i]==0) cnt++; if(a[2]/i<1500000&&a[2]%i==0&&book[a[2]/i]==0) cnt++; if(a[3]/i<1500000&&a[3]%i==0&&book[a[3]/i]==0) cnt++; if(cnt>=2){            Set=i;  Break; }    }     for(intI=1; i<=n+1; i++){        if(a[i]%Set!=0) {printf ("%lld", A[i]); return 0; }        if(book[a[i]/Set]) {printf ("%lld", A[i]); return 0; }    }    return 0;}

 

Halloween tickets.

Contact Us

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.