This summer, Tang seniors and his girlfriend to travel to Xiamen, where they are surprised to find a snack called "Shrimp rip Egg", the practice is to put the shrimp into the egg seasoning and cooked, so that the protein can cover the smell of shrimp, while ensuring the balance of nutrition.
Love to think about the Tang seniors at this time think of the N-part shrimp and egg lovers package (each of the 2 shrimp scrambled eggs), now has the allocation method is as follows: From this 2xn shrimp pull eggs out of x, so that x and N greatest common divisor is 1, wherein X>n and X<2XN, to satisfy the condition of all x's.
Input
There are multiple sets of sample samples, each set of samples to enter a T (T<=50) represents the number of n will be entered, and then the T line of an integer n (0<=n<=10) Output
For test sample input T, output T line
I act case #i: Result
Specific output reference sample output is as follows sample input 2 6 8 3 2 9 sample output case #1: #2: + CAs E #1:3 case #2: BA case #3: +/-+
This is my first question, for beginners or more difficult to a problem but the code is still very short here is not detailed introduction Euler function, do not understand please Baidu
Euler function to find less than N and The number of numbers with n coprime
because less than N and the number of n coprime are paired (such as X and N coprime, then n-x must also be with n coprime), so less than meet the conditions of the Euler (n)/2 pair, each pair of and n can know that less than N and all the sum of n coprime is N*euler (n)/ 2 (Euler (n) represents the value of the Euler function of N)
and this topic is more than n is less than 2n results then "2n*euler (2n)/2" is all less than 2n and the sum of n coprime with this value minus "N*euler (n)/2" is the result of the topic requirements You can do it here, and notice that the data range given by the topic explodes int
Small expansion: the use of Euler functions as the property of the integrable function (the integrable function is f (x*y) = f (x) *f (y)) so the answer can be expressed as "2n*euler (2n)/2-n*euler (n) /2 "=" 2n*euler (n)-n*euler (n)/2 "= " 3xn*euler (n)/2 "
My 0ms code is as follows:
#include <cstdio>
#include <algorithm>
#define LL Long Long
using namespace std;
int Get_ans (int n) {
int ans = n;
int tmp = n;
for (int i=2; i*i<=tmp; ++i) {
if (n% i = = 0) {
ans = ans/i* (i-1);
n/= i;
while (n% i = = 0)
n/= i;
}
}
if (n > 1)
ans = ans/n* (n-1);
return ans;
}
int main (void) {
int T, n;
while (scanf ("%d", &t)! = EOF) {
for (int _=1; _<=t; ++_) {
scanf ("%d", &n);
printf ("Case #%d:%lld\n", _, 3ll*n*get_ans (n)/2);
}
}
return 0;
}