"Bzoj" 2818:GCD (Euler function/Möbius)

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=2818

I am very SB lost the original to do a question up.

In fact, the problem can be more simple.

Set

$ $f [i]=1+2 \times \phi (i) $$

So the answer is

$$\sum_{p is prime number} f[n/p]$$

I lost the original question ... Don't write it.

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x)? puts ("Error"): 0) Inline const int Getint () {int r=0, k=1; char C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; } #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) const int N=10000005;int p[n], CNT, np[n], mu[n], g[n], Sum[n];voID init () {Mu[1]=1;for2 (I, 2, N) {if (!np[i]) p[++cnt]=i, Mu[i]=-1, G[i]=1;for1 (J, 1, CNT) {int t=p[j]*i; if (t>=n) break ; Np[t]=1;if (i%p[j]==0) {mu[t]=0; g[t]=mu[i]; break;} Mu[t]=-mu[i]; G[t]=mu[i]-g[i];}} For2 (i, 1, N) sum[i]=sum[i-1]+g[i];} int main () {init (); int n=getint (); ll ans=0;int pos;for (int i=1; i<=n; i=pos+1) {pos=min (n/(n/i), n/(n/i)); ans+= (LL) ( SUM[POS]-SUM[I-1]) * (n/i) * (n/i);} printf ("%lld\n", ans); return 0;}

  

Description

Given an integer n, 1<=x,y<=n and gcd (x, y) are prime
Number pairs (x, y) how many pairs.

Input

An integer n

Output

Title

Sample Input4

Sample Output4hint

Hint

For examples (2,2), (2,4), (3,3), (4,2)


1<=n<=10^7

Source

Hubei Province Team Mutual test

"Bzoj" 2818:GCD (Euler function/Möbius)

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.