HDU-1286 F-Find new friends

Source: Internet
Author: User

F-Find new friends

The new Year is coming, "Pig Head Help Association" ready to engage in a party, already know the existing member N, the member from 1 to n number, the president of the number is N, and the president is an old friend, then the member's number affirmation and N has more than 1 of the convention number, otherwise are new friends, now the president would like to know how 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), representing 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

#include <stdio.h>

#include <string.h>

#include <cstring>

#define MAX 32768

int A[max];

int main ()

{

int n,m,sum;

scanf ("%d", &n);

while (n--)

{

scanf ("%d", &m);

sum=0;

memset (A,0,sizeof (a));//Array zeroing

int i,j;

for (i=2;i<=m/2;i++)

{

if (m%i==0)

{

for (j=i;j<m;j+=i)//There is a minimum number of conventions to save 1

A[j]=1;

}

}

for (i=2;i<m;i++)

{

if (a[i]==0)//Not 1 is a new friend

sum++;

}

printf ("%d\n", sum+1);

}

return 0;

}

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.