Hdoj 1286 Find new friends

Source: Internet
Author: User

Find new friendsTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9383 Accepted Submission (s): 4970


Problem description New Year is coming, "pig head to help the 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 member's number affirmation and N has more than 1 of the convention number, otherwise are new friends , now the president wants to know how many new friends there are? Please make up the program gang length calculation.
The first line of input 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 out of a line, so that a total of CN line output.

Sample Input
22560824027

Sample Output
768016016 Code:
#include <stdio.h>int E (int n) {int a=n,res=n;for (int i=2;i*i<=a;i++) {if (a%i==0) {res=res/i* (i-1);// Divide first to prevent intermediate data overflow;}while (a%i==0) {a=a/i;}} if (a>1) {res=res/a* (A-1);} return res;} int main () {int t,n;scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf ("%d\n", E (n));} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj 1286 Find new friends

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.