一個數如果恰好等於它的因子之和,這個數就稱為 "完數 "。例如6=1+2+3.編程     找出1000以內的所有完數。


package a;

public class Wanshu {

    public static void main(String[] args) {
        
        for (int i = 1; i <= 1000; i++)
        {
            int sum=0;
            for (int j = 1; j < i; j++)
            {
            if(i%j==0)
            {
                sum+=j;
            }
                
            }
            if(i==sum)
            {
                System.out.println(i);
            }
        }

    }

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM