Hdoj 1286 Find new friends

Source: Internet
Author: User
Tags printf
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>


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.