• NYOJ 212


     

    K尾相等数

    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
     
    描述
    输入一个自然数K(K>1),如果存在自然数M和N(M>N),使得K^M和K^N均大于等于1000,且他们的末尾三位数相等,则称M和N是一对“K尾相等数”。下面请编程求出M+N最小的K尾相等数。
     
    输入
    第一行包含一个正整数T,T<10000,表示有T组数据;
    随后有N行,每行包括一个整数K(K<2*10^10);
    输出
    对于输入的每个整数K,输出对应的M+N的最小值;
    样例输入
    1
    2
    样例输出
    120
     1  
     2 #include <stdio.h>
     3 #include <string.h>
     4 int main()
     5 {
     6     int i,j,k,T;
     7     int num;
     8     int res = 1,step;
     9     scanf("%d",&T);
    10     int ans[1000];
    11     while(T--)
    12     {
    13         res = 1;
    14         step = 0;
    15         memset(ans,0,sizeof(ans));
    16         scanf("%d",&num);        
    17         while(res<1000)
    18         {
    19             step++;
    20             res *= num;
    21         }
    22         num %= 1000;
    23         res %= 1000;
    24         ans[res] = step;
    25         while(1)
    26         {
    27             res = res*num%1000;
    28             step++;
    29             if(ans[res])
    30             {
    31                 printf("%d\n",ans[res]+step);
    32                 break;
    33             }
    34             else
    35                 ans[res] = step;
    36         }
    37     }
    38     return 0;
    39 }
    40             
    41             
    42         
    43         
  • 相关阅读:
    -for循环案例(下)
    for循环案例(上)
    for循环
    判断语句案例
    判断语句
    操作符优先级
    windows 下安装图片标注软件 labelling和出错解决
    tf-faster rcnn
    目标检测——Faster R-CNN 详解、Pytorch搭建、训练自己的数据集
    java idea 配置安装
  • 原文地址:https://www.cnblogs.com/hxsyl/p/2650581.html
Copyright © 2020-2023  润新知