zoukankan      html  css  js  c++  java
  • 自守数

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

     接口说明


    /*
    功能: 求出n以内的自守数的个数


    输入参数:
    int n

    返回值:
    n以内自守数的数量。
    */

     public static int CalcAutomorphicNumbers( int n)

    {
    /*在这里实现功能*/

    return 0;
    }

    输入描述:

    int型整数

    输出描述:

    n以内自守数的数量。

    输入例子:

    2000
    输出例子:
    8
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            while(in.hasNext()) {
                int n = in.nextInt();
                System.out.print(findNum(n));
                
            }
        }
    
        private static int findNum(int n) {
            int squl = 0;
            int num = 1; // 0是自守数
            for(int i = 1; i <= n; i++) {
                squl = i * i;
                int yu = 0;
                int result = 0;
                int count  = 0;
                while(squl > 0) {
                    yu = squl % 10;
                    result +=  yu * Math.pow(10, count);
                    if(result == i) {
                        num ++;
                        break;
                    }
                    count ++;
                    squl = squl / 10;
                }
            }
            
            return num;
        }
    }
                 
                
  • 相关阅读:
    webpack入门+react环境配置
    mailto: HTML e-mail 链接
    IE兼容性手册
    浏览器内核Trident/Gecko/WebKit/Presto
    抓包
    js页面埋点
    http返回码
    meta
    img和css背景的选择
    谈谈Web前端工程师的定位
  • 原文地址:https://www.cnblogs.com/zywu/p/5815410.html
Copyright © 2011-2022 走看看