题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include<stdio.h>
int main()
{
int num = 0;
scanf("%d", &num);
int count = 0;
for(int i = 0; i <= num; i++)
{
int j = 1;
int tmp = i*i;
if(i == 0 || i == 1)
{
count++;
}
else
{
while(tmp >= j)
{
if(tmp%j == i)
{
count++;
break;
}
j *= 10;
}
}
}
printf("%d\n", count);
return 0;
}
int main()
{
int num = 0;
scanf("%d", &num);
int count = 0;
for(int i = 0; i <= num; i++)
{
int j = 1;
int tmp = i*i;
if(i == 0 || i == 1)
{
count++;
}
else
{
while(tmp >= j)
{
if(tmp%j == i)
{
count++;
break;
}
j *= 10;
}
}
}
printf("%d\n", count);
return 0;
}