第六届蓝桥杯 省赛 JavaB组 立方变自身

    xiaoxiao2021-03-25  94

    观察下面的现象,某个数字的立方,按位累加仍然等于自身。 1^3 = 1  8^3  = 512    5+1+2=8 17^3 = 4913   4+9+1+3=17 ... 请你计算包括1,8,17在内,符合这个性质的正整数一共有多少个?

    请填写该数字,不要填写任何多余的内容或说明性的文字。

    public class Main { public static void main(String[]args){ int count=0; int temp; int add=0; for(int i=0;i<100;i++){//统计100以内的数量 temp=(int) Math.pow(i, 3);//幂次方Math.pow(),返回double while(temp>0){ add+=temp; temp=temp/10; } if(add==temp){ System.out.println(i); } } } }

    转载请注明原文地址: https://ju.6miu.com/read-16029.html

    最新回复(0)