守形数
题目截图:

思路:
首先,只有尾数为 0,1,5,6的数才可能为守形数,所以其他可以直接排除。然后对其他的数进行判断即可。
代码如下:
1 /*
2 守形数
3 */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <math.h>
8 #include <stdlib.h>
9 #include <time.h>
10 #include <stdbool.h>
11
12 int main() {
13 int N;
14 while(scanf("%d", &N) != EOF) {
15 int g = N%10; // 提取尾数
16 // 只有尾数为 0,1,5,6 的数才可能为守形数
17 if(g==1 || g==5 || g==6 || g==0) {
18 int t = N*N;
19 int ans=10; // 用来提取低位部分
20 if(N > 10) {
21 ans = 100;
22 }
23 if(t%ans == N) { // 判断是否是守形数
24 printf("Yes!\n");
25 } else {
26 printf("No!\n");
27 }
28 } else {
29 printf("No!\n");
30 }
31 }
32
33 return 0;
34 } 相关推荐
89243453 2020-08-24
Erick 2020-08-21
earthhouge 2020-07-19
klarclm 2020-06-14
拉斯厄尔高福 2020-06-02
Jaystrong 2020-06-02
hongsheyoumo 2020-06-02
twater000 2020-05-30
adonislu 2020-05-17
Haopython 2020-05-09
浅梦墨汐 2020-05-12
shenwenjie 2020-05-09
fengjing81 2020-05-08
lihuifei 2020-05-04
wbczyh 2020-05-03
LychieFan 2020-04-30
luckymaoyy 2020-04-25
Cypress 2020-04-25