zoukankan      html  css  js  c++  java
  • 完数

    一个数如果恰好等于它的因子之和,这个数就称为"完数"。 例如,6的因子为1、2、3,而6=1+2+3,因此6是"完数"。 编程序找出N之内的所有完数,并按下面格式输出其因子:

    输入

    N

    输出

    ? its fastors are ? ? ?

    样例输入

    1000

    样例输出

    6 its fastors are 1 2 3
    28 its fastors are 1 2 4 7 14
    496 its fastors are 1 2 4 8 16 31 62 124 248
    #include <stdio.h>
    int main(){
    int n, i, i2, j;
    int a[] = {6, 28, 496, 8128, 33550336};
    while (scanf("%d", &n) == 1){
       for (i=0; i<5; i++){
        if (a[i] <= n){
         printf("%d ", a[i]);
         printf("its fastors are 1 ");
         i2 = a[i]/2;
         for (j=2; j<=i2; j++){
          if (a[i]%j == 0){
              if(j!=i2){
           printf("%d ", j);
                 }
              else
              {
             printf("%d", j);
              }
          }
         }
         printf("
    ");
        }
       }
    }
    return 0;
    }
     
     
  • 相关阅读:
    专题三--1005
    专题三--1009
    专题三--1017
    背包九讲
    专题三--1003
    专题三--1004
    专题三--1015
    [洛谷P1220]关路灯
    [洛谷P1776]宝物筛选
    [USACO14JAN]Recording the Moolympics
  • 原文地址:https://www.cnblogs.com/Lazy-Cat/p/9838252.html
Copyright © 2011-2022 走看看