poj1528---(number theory)

Source: Internet
Author: User

Test instructions: A number in addition to all factors other than itself, the resulting number if less than itself, output deficient, otherwise output abundant, if equal, output perfect

The core of the problem: to ask for all the factors other than itself

int sum=1, I;             for (i=2; i<n;i++)           {               if(n%i==0)                   sum+ =i;           }

A number if divided by less than his number starting from 2, if n%i==0, stating that can n be divisible by I, I was one of his factors, sum+=i, again let I++,i to n-1 end

#include <stdio.h>#include<stdlib.h>intMain () {intN; printf ("Perfection output\n");  while(SCANF ("%d", &n)! =EOF) {        if(n==0) {printf ("END of output\n");  Break; }        Else if(n==1) printf ("%5d deficient\n", N); Else        {           intsum=1, I;  for(i=2; i<n;i++)           {               if(n%i==0) Sum+=i; }           if(sum<n) printf ("%5d deficient\n", N); Else if(sum==n) printf ("%5d perfect\n", N); Elseprintf"%5d abundant\n", N); }    }}

poj1528---(number theory)

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.