zoukankan      html  css  js  c++  java
  • 杭电1058

    0~2000000000中能被2,3,5,7整除的数

    View Code
     1 //杭电1058
     2 /*
     3 1              The 1st humble number is 1.
     4 2              The 2nd humble number is 2.
     5 3              The 3rd humble number is 3.
     6 4              The 4th humble number is 4.
     7 11             The 11th humble number is 12.
     8 12             The 12th humble number is 14.
     9 13             The 13th humble number is 15.
    10 21             The 21st humble number is 28.
    11 22             The 22nd humble number is 30.
    12 23             The 23rd humble number is 32.
    13 100            The 100th humble number is 450.
    14 1000           The 1000th humble number is 385875.
    15 5842           The 5842nd humble number is 2000000000.
    16 
    17 
    18 */
    19 #include<stdio.h>
    20 
    21 #define N 5843
    22 int f[N];
    23 int min(int a,int b,int c,int d)
    24 {
    25     int x,y,z;
    26     x=a>b?b:a;
    27     y=c>d?d:c;
    28     z=x>y?y:x;
    29     return z;
    30 }
    31 int main()
    32 {
    33     int n,a,b,c,d,i;
    34     f[1]=1;a=b=c=d=1;
    35     for(i=2;i<=N;i++)
    36     {
    37         f[i]=min(f[a]*2,f[b]*3,f[c]*5,f[d]*7);//将所有符合条件的数用数组存储起来
    38         if(f[i]==f[a]*2)
    39             a++;
    40         if(f[i]==f[b]*3)
    41             b++;
    42         if(f[i]==f[c]*5)
    43             c++;
    44         if(f[i]==f[d]*7)
    45             d++;
    46     }
    47 
    48     while(scanf("%d",&n),n!=0)
    49     {
    50         if(n%100==11||n%100==12||n%100==13)
    51         printf("The %dth humble number is %d.\n",n,f[n]);
    52 
    53         else
    54         {
    55             if(n%10==1)
    56             printf("The %dst humble number is %d.\n",n,f[n]);
    57         else if(n%10==2)
    58             printf("The %dnd humble number is %d.\n",n,f[n]);
    59         else if(n%10==3)
    60         printf("The %drd humble number is %d.\n",n,f[n]);
    61         else
    62         printf("The %dth humble number is %d.\n",n,f[n]);
    63         }
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    理解javascript中的Array类型
    解决EF 4.0 中数据缓存机制
    vim学习之旅01-文本搜索并高亮显示
    Quartz.Net 学习之路02 初探Quartz.Net
    Quartz.Net 学习之路01 安装Quartz.Net
    EasyUI这个框架用了好久了,总结一下遇到的问题和解决方法
    记录剪切板
    如何将Unicode字符转换成简体字
    ass字幕转换成文本文件
    Change WORDS
  • 原文地址:https://www.cnblogs.com/zlyblog/p/2578098.html
Copyright © 2011-2022 走看看