- #include<bits/stdc++.h>
- using namespace std;
- int compute(int a)
- {
- int sum=0;
- for(int i=1 ; i<a ; i++)
- {
- string str = to_string(i);
- int l = str.length();
- if(l == 1)
- {
- cout << i << endl;
- sum+=i;
- }
- if(l == 2)
- {
- if(pow(str[0]-'0',2)+pow(str[1]-'0',2) == i)
- {
- cout << i << endl;
- sum+=i;
- }
- }
- if(l == 3)
- {
- if(pow(str[0]-'0',3)+pow(str[1]-'0',3)+pow(str[2]-'0',3) == i)
- {
- cout << i << endl;
- sum+=i;
- }
- }
- }
- return sum;
- }
- int main()
- {
- int n;
- cin >> n;
- cout << compute(n) << endl;
- return 0;
- }
複製代碼 |