题解 | #自守数#

自守数

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int num = in.nextInt();
            int count = 1;
            int countBit = 10;
            int temp;

            for(int i = 1; i <= num; i++){
                temp = i;
                countBit = 10;
                while(temp / 10 != 0){
                    countBit *= 10;
                    temp /= 10;
                }
                if((i * i - i) % countBit == 0 ){

                    count++;
                }
            }
            System.out.println(count);
        }
    }
}

全部评论

相关推荐

今天 19:25
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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