Huawei OD Computer Test-Autonomous Numbers (C++ & Java & JS & Python)

describe

An automorphic number is a natural number whose mantissa of the square of a number is equal to the number itself. For example: 25^2 = 625, 76^2 = 5776, 9376^2 = 87909376. Request the number of automorphic numbers within n (including n)

Data range: 1≤�≤10000 1≤n≤10000 

Enter description:

int type integer

Output description:

The number of automorphic numbers within n.

Example 1

enter:

6

Output:

4

illustrate:

There are four automorphic numbers 0, 1, 5, and 6      

Example 2

enter:

1

Output:

2

illustrate:

There are two automorphic numbers 0 and 1     

Java:

import java.util.*;
public class Main {
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            while(sc.hasNext()){
                int n = sc.nextInt();
                int count = 0;
                for(int i=0;i<=n;i++){
                    int sum =i*i;
                    Strin

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132895692