The guard of Honor asks for the value of Euler function within n

Source: Internet
Author: User

I-Honor GuardTime limit:10000MS Memory Limit:265216KB 64bit IO Format:%lld &%llu SubmitStatus

Description

As a sports Commissioner, C June is responsible for the training of the honor guard.       Guard of Honor is composed of students of N * N of the square, in order to ensure that the procession uniform, c June will follow the guard of Honor's left rear, according to the number of students in the line of sight to determine whether the team is neat (such as). Now, C-June wants you to tell him the number of students you can see when the team is neat.

Input

A total of a number n.

Output

A total of a number, that is, c June should see the number of students.

Sample Input

4

Sample Output

9

Hint

"Data size and conventions" for 100% of data, 1≤n≤40000


#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath > #include <sstream> #define N 50900using namespace Std;typedef long long ll;int vis[n],pri[n];int cnt;void init ()    {cnt=0;        for (int i=2;i<=n;i++) {if (vis[i]==0) pri[cnt++]=i;            for (int j=0;j<cnt && i*pri[j]<n;j++) {vis[i*pri[j]]=1;        if (i%pri[j]==0) break;    }}}int Main () {int n;    Init ();            while (~SCANF ("%d", &n)) {if (n==1) {puts ("1");        Continue        }//for (int i=0;i<100;i++)//cout<<pri[i]<< "";        int num;        int ans=0;            for (int i=1;i<n;i++)//n Euler function {num=i;            for (int j=0;j<cnt && pri[j]<=40009;j++) if (i%pri[j]==0) num=num* (pri[j]-1)/pri[j];            cout<< "num=" <<num<<endl;        Ans+=num;      }  printf ("%d\n", ans*2+1); } return 0;}






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The guard of Honor asks for the value of Euler function within n

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.