首页
学习
活动
专区
圈层
工具
发布
29 篇文章
1
PAT (Basic Level) Practice (中文)1047 编程团体赛
2
PAT (Basic Level) Practice (中文)1083 是否存在相等的差
3
PAT (Basic Level) Practice (中文)1082 射击比赛
4
PAT (Basic Level) Practice (中文)1081 检查密码
5
PAT (Basic Level) Practice (中文)1077 互评成绩计算
6
PAT (Basic Level) Practice (中文)1076 Wifi密码
7
PAT (Basic Level) Practice (中文)1064 朋友数
8
PAT (Basic Level) Practice (中文)1063 计算谱半径
9
PAT (Basic Level) Practice (中文)1057 数零壹
10
PAT (Basic Level) Practice (中文)1056 组合数的和
11
PAT (Basic Level) Practice (中文)1042 字符统计
12
PAT (Basic Level) Practice (中文)1041 考试座位号
13
PAT (Basic Level) Practice (中文)1023 组个最小数
14
PAT (Basic Level) Practice (中文)1022 D进制的A+B
15
PAT (Basic Level) Practice (中文)1019 数字黑洞
16
PAT (Basic Level) Practice (中文)1007 素数对猜想
17
PAT (Basic Level) Practice (中文)1091 N-自守数
18
PAT (Basic Level) Practice (中文)1026 程序运行时间
19
PAT (Basic Level) Practice (中文)1061 判断题
20
PAT (Basic Level) Practice (中文)1086 就不告诉你
21
PAT (Basic Level) Practice (中文)1016 部分A+B
22
PAT (Basic Level) Practice (中文)1012 数字分类
23
PAT (Basic Level) Practice (中文)1013 数素数
24
PAT (Basic Level) Practice (中文)1011 A+B 和 C
25
PAT (Basic Level) Practice (中文)1009 说反话
26
PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题
27
PAT (Basic Level) Practice (中文)1006 换个格式输出整数
28
PAT (Basic Level) Practice (中文)1004 成绩排名
29
PAT (Basic Level) Practice (中文)1002 写出这个数

PAT (Basic Level) Practice (中文)1091 N-自守数

1091 N-自守数

如果某个数 K 的平方乘以 N 以后,结果的末尾几位数等于 K,那么就称这个数为“N-自守数”。例如 3×922=25392,而 25392 的末尾两位正好是 92,所以 92 是一个 3-自守数。

本题就请你编写程序判断一个给定的数字是否关于某个 N 是 N-自守数。

输入格式:

输入在第一行中给出正整数 M(≤20),随后一行给出 M 个待检测的、不超过 1000 的正整数。

输出格式:

对每个需要检测的数字,如果它是 N-自守数就在一行中输出最小的 N 和 NK2 的值,以一个空格隔开;否则输出 No。注意题目保证 N<10。

输入样例:

3 92 5 233

输出样例:

3 25392 1 25 No

代码:

代码语言:javascript
复制
#include<stdio.h>
int fun(int K)
{
    int wei=fun_1(K);
  //  printf("wei==%d\n",wei);
    int N;
    int l=1;
    for(N=1;N<10;N++)
    {
        int p=fun_2(N*K*K,wei);
       // printf("p==%d\n",p);
        if(p==K) {
            l=0;
            //printf("%d %d\n",N,N*K*K);
            break;
        }
    }
    if(l==1) return -1;
    else return N;
}
int fun_1(int n)
{
    int temp=0;
    while(n)
    {
        n/=10;
        temp++;
    }
    return temp;
}

int fun_2(int n,int wei)
{
    int i=1;
    int t=0;
    int sum=0;
    int *arr=(int*)malloc(sizeof(int)*wei);
    while(i<=wei)
    {
        int temp=n%10;
        arr[t++]=temp;
        n/=10;
        i++;
    }
    for(i=t-1;i>=0;i--)
        sum=sum*10+arr[i];
    return sum;
}
int main()
{
    int M;
    int Ki[22];
    int i;
    scanf("%d",&M);
    for(i=0;i<M;i++)
    {
        scanf("%d",&Ki[i]);
    }
    for(i=0;i<M;i++)
    {
        int t=fun(Ki[i]);
        if(t<0) printf("No\n");
        else printf("%d %d\n",t,t*Ki[i]*Ki[i]);
    }
    return 0;
}
下一篇
举报
领券