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;
        }
    }
                 
                
  • 相关阅读:
    rsync特性
    01 什么是爬虫
    celery的使用
    redis的使用
    GIT使用大全
    多项式的高级运算
    SP1557 GSS2
    题解 CF997E 【Good Subsegments】
    P3920 [WC2014]紫荆花之恋
    题解 P3750 【[六省联考2017]分手是祝愿】
  • 原文地址:https://www.cnblogs.com/zywu/p/5815410.html
Copyright © 2011-2022 走看看