题解 | #自守数#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <stdio.h>
#include <string.h>
#include <math.h>
//自守数 判断是几位 平方后对10的位数次方取余
//87909376 9376 87900000%10000
//pow(),需要加载math.h
int isself(int n);
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
int count = 0;
for (int i = 0; i <= n; i++)
if (isself(i) == 1)
count++;
printf("%d\n", count);
}
return 0;
}
int isself(int n)
{
int ret = 0;
int digit = 0;
int cmpn = n * n - n;
while (n != 0)
{
digit++;
n /= 10;
}
int rank = pow(10, digit);
if (cmpn % rank == 0)
{
ret = 1;
}
return ret;
}