木仙花數

木仙花數c++

題目描述:spa

定義木仙花數爲知足如下條件的數:ci

假設正整數 x 爲木仙花數,當且僅當存在一個小於等於 x 的正整數 y 使得 floor(x/y)=y 。floor表示往下取整。it

給定正整數 n ,求小於等於 n 的木仙花數個數。class

輸入格式:view

一個正整數n。vi

輸出格式:co

一個數表示答案。

樣例輸入1:

4

樣例輸出1:

2

約定:

1<=n<=5000

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n=0;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=i;j++){
      int k=floor(i/j);
      if(k==j){
      ans++;
    }
   }
  }
  cout<<ans<<endl;
}

相關文章
相關標籤/搜索