fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main (String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = scanner.nextInt();
  7. int m = scanner.nextInt();
  8. for(int i=1; i<n; i++) {
  9. int a=i;
  10. int sum=0;
  11. while(a!=0) {
  12. sum+=a%10;
  13. a/=10;
  14. }
  15. if(sum*sum==m)
  16. System.out.print(i+" ");
  17. }
  18. }
  19. }
Success #stdin #stdout 0.07s 2184192KB
stdin
1000 1
stdout
1 10 100