题解 | #自守数#

自守数

https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int i = 0; i <= n; i++){
            if(isSelfConservative(i)){
                count++;
            }
        }
        System.out.print(count);
    }
    public static boolean isSelfConservative(int num){
        String s = new String(""+num);
        int sqr = num*num;
        int bits = s.length();
        int tens = (intMath.pow(10,bits);
        int tail = sqr%tens;
        if(num==tail){
            return true;
        }
        return false;
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务