Find new friends
Problem Description
The new Year is coming, "Pig-head Association" ready to engage in a party, already know the existing member N, the member from 1 to n number,
Where the president's number is N, and the president is an old friend, then the number of the member must be greater than 1 of the number of conventions,
Otherwise they are new friends, and now the president wants to know how many new friends there are. Please make up the program gang length calculation.
Input
The first line is the number of groups of test data cn (case number,1<cn<10000), followed by a CN-line positive integer n (1<n<32768),
Indicates the number of members.
Output
For each n, the number of new friends is output, so there is a CN line output.
Sample Input
2
25608
24027
Sample Output
7680
16016
Euler functions
<span style= "FONT-SIZE:18PX;" > #include <stdio.h>
#include <string.h>
int main ()
{
int n,x,i,j,a[40000];
scanf ("%d", &n);
while (n--)
{
scanf ("%d", &x);
memset (A,-1,sizeof (a));
For (i=2, i<x; i++)
{
if (x%i==0) for
(j=1; i*j<x; j + +)
a[i*j]=0;
}
int sum=0;
for (i=2; i<x; i++)
if (a[i]==0)
sum++;
printf ("%d\n", x-sum-1);
}
return 0;
} </span>
This is the use of the table method, but timed out, but you can understand the idea.
<span style= "FONT-SIZE:18PX;" ># include<stdio.h>
int fab (int x,int y)
{
int t,a,b;
a=x,b=y;
while (b!=0)
{
t=a%b;
a=b;
b=t;
}
if (a==1)
return 0;
else
return y;
}
int main ()
{
int n,i,a[33000];
scanf ("%d", &n);
while (n--)
{
int m,t=0;
scanf ("%d", &m);
for (i=1;i<m;i++)
{
a[i]=fab (m,i);
}
for (i=1;i<m;i++)
if (a[i]==0)
t++;
printf ("%d\n", t);
}
} */</span>