fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. unsigned n, m, t, sum, i=1;
  6. cin>>n>>m;
  7. for(i;i<n;i++){
  8. t=i;
  9. sum=0;
  10. while(t!=0){
  11. sum+=t%10;
  12. t/=10;
  13. }
  14. if(sum*sum==m)cout<<i<<" ";
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 3472KB
stdin
1234 9
stdout
3 12 21 30 102 111 120 201 210 300 1002 1011 1020 1101 1110 1200