题解 | #完全数计算#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.io.*;
import java.util.*;
public class Main {
/*************************
功能: 求出n以内的自守数的个数
输入参数:
int n
返回值:
n以内自守数的数量。
*/
public static int CalcAutomorphicNumbers(int n)
{
int count = 0, base = 1;
for (int i = 0; i <= n; i++)
{
if (i >= base) {
base *= 10;
}
if (i * i % base == i) {
count++;
}
}
return count;
}
public static void main (String [] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String line = null;
while ((line = f.readLine()) != null)
{
int n = Integer.parseInt(line);
int res = CalcAutomorphicNumbers(n);
out.println(res);
}
out.close();
f.close();
}
}


京东工作强度 412人发布