Lightoj 1370 Bi-shoe and Phi-shoe (Euler function)

Source: Internet
Author: User

Test instructions: The topic gives a Euler function value f (x), let's ask >= the minimum number N of this function value, so that f (N) >= f (x);

Analysis: There are two ways to do this topic. First, the brute force forms the Euler function table, then adjusts it to order, and then builds a new table to record the minimum Euler value that satisfies the condition.

The second, according to the properties of Euler functions, for a prime n,f (N) = N-1; Then assume that the first prime greater than N is M, its function value is M-1, at this time, any number between (N,M) is composite, and their Euler value must be less than M-1, so we want to find the minimum number of the problem, can be found from the number of the first one, until we find the initial prime, This number is the minimum value we are looking for.

Note: C + + compiler does not support%i64, only support%LLD, I because of this WA a few times, pay attention to compiler requirements and the description above the topic.

The code is as follows:

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;#defineMAXN 1500100#defineLL Long LongLL PRIME[MAXN+ -];voidMake () {memset (prime,1,sizeof(prime)); prime[1] =0;  for(inti =2; I <= MAXN; i++)    {        if(Prime[i]) { for(intj = i*2; J <= Maxn; J + =i) {prime[j]=0; }        }    }}intMain () {LL T,n,num,ca=0;    Make ();    LL sum; scanf ("%lld",&t);  while(t--) {scanf ("%lld",&N); Sum=0;  for(inti =0; I < n; i++) {scanf ("%lld",&num);  for(LL j = num+1;true; J + +)            {                if(Prime[j]) {//printf ("the min one =%d\n", j);Sum + =J;  Break; }}} printf ("Case %LLD:",++CA); printf ("%lld xukha\n", sum); }    return 0;}

Lightoj 1370 Bi-shoe and Phi-shoe (Euler function)

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.