3

金仙花数

 3 years ago
source link: http://www.cnblogs.com/pxy071128fzm/p/13687139.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

金仙花数

题目描述:

定义金仙花数 x 满足以下性质:

X 的各个数位之和大于等于 20,且 x 的各个数位乘积大于等于 162 。

给定 n ,求小于等于 n 的金仙花数个数。

输入格式:

一个正整数 n 。

输出格式:

一个数表示答案。

样例输入1:

299

样例输出1:

1

约定:

1<=n<=100000

#include<bits/stdc++.h>

using   namespace   std;

int   pxy( int   m){

   int   a[7]={0};

   int   n=m;

   int   k=0;

   int   b[7];

   for ( int   i=1;i<=6;i++){

     a[i]=n%10;

     n=n/10;

   }

   for ( int   i=1;i<=6;i++){

     k+=a[i];

   }

   return   k;

}

int   fzm( int   m){

   int   a[5]={0};

   int   n=m;

   int   k=1;

   int   b[5]={0};

   for ( int   i=0;i<=5;i++){

     a[i]=n%10;

     if (n>0&&a[i]>=0){

       b[i]=1;

     }

     n=n/10;

   }

   for ( int   i=0;i<=5;i++){

     if (b[i]==1){

       k=k*a[i];

     }

   }

   return   k;

}

int   main(){

   int   n,ans=0;

   cin>>n;

   for ( int   i=1;i<=n;i++){

     int   l1=fzm(i);

     int   t1=pxy(i);

     if (l1>=162){

       if (t1>=20){

         ans++;

       }

     }

   }

   cout<<ans<<endl;

}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK