int main() { int i,a,b,c,d; printf(“0\n1\n”); for(i=11;i<10000;i++) { if(i<100) { a=i%10; b=i/10; if(a<5&&b<5) continue; else if(aaaa+bbbb==i) printf(“%d\n”,i); } if(i>100&&i<1000) { a=i%10; b=i/10%10; c=i/100; if(a<5&&b<5&&c<5) continue; else if(aaaa+bbbb+cccc==i) printf(“%d\n”,i); } if(i>=1000&&i<10000) { a=i%10; b=i/10%10; c=i/100%10; d=i/1000; if(a<5&&b<5&&c<5&&d<5) continue; else if(aaaa+bbbb+cccc+ddd*d==i) printf(“%d\n”,i); }
} return 0;
}
我的想法比较朴素,就是一个个找。代码如下:
using namespace std; inline unsigned four_times(unsigned i) { return i * i * i * i; } inline bool waterlilly(unsigned const& is) { unsigned i = is, temp = 0; while (i) { temp += four_times(i % 10); i /= 10; } if (is == temp) return true; return false; } int main() { vector<unsigned> vuzu; for (unsigned i = 0; i < 10000; ++i) { if (waterlilly(i)) vuzu.push_back(i); } for (auto const& i : vuzu) cout << i << ' '; }
using namespace std;
bool isok(int n){ int sum = 0, s = n; while(n > 0){ int left = n % 10; sum += left * left * left * left; n /= 10; } if(sum == s) return true; return false; }
int main(){ for(int i = 0; i < 10000; i ++) if(isok(i)) cout << i << endl; return 0; }
for v in range(10000): t = str(v) sum = 0 for i in t: sum = sum + pow(int(i),4) if(sum == v): print(v)
int main() {
for(int i=0;i<10000;i++) { int sum=0; for(int j=i;j>0;j/=10) { sum+=(j%10)*(j%10)*(j%10)*(j%10); } if(sum==i) printf("%d\n",i); }
include
include
int main()
{
int i,a,b,c,d;
printf(“0\n1\n”);
for(i=11;i<10000;i++)
{
if(i<100)
{
a=i%10;
b=i/10;
if(a<5&&b<5) continue;
else if(aaaa+bbbb==i) printf(“%d\n”,i);
}
if(i>100&&i<1000)
{
a=i%10;
b=i/10%10;
c=i/100;
if(a<5&&b<5&&c<5) continue;
else if(aaaa+bbbb+cccc==i) printf(“%d\n”,i);
}
if(i>=1000&&i<10000)
{
a=i%10;
b=i/10%10;
c=i/100%10;
d=i/1000;
if(a<5&&b<5&&c<5&&d<5) continue;
else if(aaaa+bbbb+cccc+ddd*d==i) printf(“%d\n”,i);
}
}
希望更好的展现?使用MarkDown!
我的想法比较朴素,就是一个个找。代码如下:
include
using namespace std;
bool isok(int n){
int sum = 0, s = n;
while(n > 0){
int left = n % 10;
sum += left * left * left * left;
n /= 10;
}
if(sum == s) return true;
return false;
}
int main(){
for(int i = 0; i < 10000; i ++)
if(isok(i))
cout << i << endl;
return 0;
}
include
int main()
{
}