自守数

题目描述

自守数是指一个数的平方的尾数等于该数自身的自然数。例如:25^2 = 625,76^2 = 5776,9376^2 = 87909376。请求出n以内的自守数的个数

输入描述:

int型整数

输出描述:

n以内自守数的数量。

输入例子:
2000
输出例子:
8
 1 import java.util.*;
 2 
 3 public class Main{
 4     public static void main(String[] args) {
 5         Scanner sc = new Scanner(System.in);
 6         while (sc.hasNext()){
 7             int n = sc.nextInt();
 8             int count = 0,len = 0;
 9             for(int i = 0;i <= n;i++){
10                 len = new Integer(i).toString().length();
11                 if(i * i %(Math.pow(10,len))== i)
12                     count++;
13             }
14             System.out.println(count);
15         } 
16     }
17 }
View Code

用到了幂函数和判断一个数有几位。

posted @ 2016-08-17 17:09  蛋蛋的守护  阅读(358)  评论(0)    收藏  举报