儀仗隊(歐拉函數模板)

來源:互聯網
上載者:User

標籤:

 1 long long euler_phi(int n) 2 { 3     int m=(int)sqrt(n+0.5); 4     int ans=n; 5     for(int i=2;i<=m;i++) 6  7         if(n%i==0) 8         { 9             ans=ans/i*(i-1);10             while(n%i==0)11                 n/=i;12         }13     if(n>1)ans=ans/n*(n-1);14     return ans;15 }

Description

  作為體育委員,C君負責這次運動會儀仗隊的訓練。儀仗隊是由學生組成的N * N的方陣,為了保證隊伍在行進中整齊劃一,C君會跟在儀仗隊的左後方,根據其視線所及的學生人數來判斷隊伍是否整齊(如)。      現在,C君希望你告訴他隊伍整齊時能看到的學生人數。

Input

  共一個數N。

Output

  共一個數,即C君應看到的學生人數。

Sample Input

  4

Sample Output

  9


Hint

【資料規模和約定】   對於 100% 的資料,1 ≤ N ≤ 40000

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include<cmath> 6 #include<sstream> 7 #include<string> 8 using namespace std; 9 long long euler_phi(int n)10 {11     int m=(int)sqrt(n+0.5);12     int ans=n;13     for(int i=2;i<=m;i++)14 15         if(n%i==0)16         {17             ans=ans/i*(i-1);18             while(n%i==0)19                 n/=i;20         }21     if(n>1)ans=ans/n*(n-1);22     return ans;23 }24 25 int main()26 {27     int n;28     long long sum=0;29     scanf("%d",&n);30     for(int i=1;i<n;i++)31        sum+=euler_phi(i);32        sum=sum*2+1;33        printf("%lld\n",sum);34     return 0;35 }

 

儀仗隊(歐拉函數模板)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.