您的位置:首页 > 其它

立方尾不变

2017-12-16 20:35 120 查看
有些数字的立方的末尾正好是该数字本身。
比如:1,4,5,6,9,24,25,....
 
请你计算一下,在10000以内的数字中(指该数字,并非它立方后的数值),符合这个特征的正整数一共有多少个。

分析:
数字的立方的末尾正好是该数字本身
数字的末尾 = 数字%(10的(数字的长度)的方)
25%10 = 5
123%10*10 = 3

代码如下:
public class a1
{
public a1(){
                        
         int count = 0;

        
for (int i =
0; i < 10000;
i++) {

 
                String
s = String.valueOf(i);

 
               if( Math.pow(i,
3)%(Math.pow(10,
s.length())) ==
i ){
 
                    System.out.println(i);
 
                 }
             
}
          System.out.printf("一共有%d个",count);
     
}
public static void main(String[]
args) {
//
TODO Auto-generated method stub
        
new a1();

          
}
 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: