fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. long n, m, t, sum;
  11. n = in.nextLong();
  12. m = in.nextLong();
  13. for(long i = 1; i < n; i++) {
  14. t = i;
  15. sum = 0;
  16. while(t != 0
  17. sum += t%10;
  18. t /= 10;
  19. }
  20. if(sum*sum == m) System.out.print(i + " ");
  21. }
  22. }
  23. }
Success #stdin #stdout 14.91s 2184192KB
stdin
1000000000 1
stdout
1 10 100 1000 10000 100000 1000000 10000000 100000000