返回列表 發帖
310:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int compute(int a)
  4. {
  5.     int sum=0;
  6.     for(int i=1 ; i<a ; i++)
  7.     {
  8.         string str= to_string(i);

  9.         int l= str.length();

  10.         if(l==1)
  11.         {
  12.             cout << i << endl;
  13.             sum+=i;
  14.         }
  15.         else if(l==2)
  16.         {
  17.             if(pow(str[0]-'0',2)+pow(str[1]-'0',2) == i)
  18.             {
  19.                 cout << i << endl;
  20.                 sum+=i;
  21.             }
  22.         }
  23.         else
  24.         {
  25.             if(pow(str[0]-'0',3)+pow(str[1]-'0',3)+pow(str[2]-'0',3) == i)
  26.             {
  27.                 cout << i << endl;
  28.                 sum+=i;
  29.             }
  30.         }
  31.     }
  32.     return sum;
  33. }
  34. int main()
  35. {
  36.     int n;
  37.     cin >> n;
  38.     cout << compute(n) << endl;
  39.     return 0;
  40. }
複製代碼
Vincent

TOP

返回列表