Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PowerSum {
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. int x = sc.nextInt();
  11. int power = sc.nextInt();
  12. rec(x,power,0,1);
  13. System.out.println(c);
  14. }
  15.  
  16. static int c = 0;
  17. static void rec(int x, int power, double d, int j) {
  18. if(x==d) {
  19. c++;
  20. return;
  21. }
  22.  
  23. for(int i = j; d+Math.pow(i, power)<=x; i++) {
  24. rec(x,power,d+Math.pow(i, power),i+1);
  25. }
  26.  
  27. }
  28. }
Add Comment
Please, Sign In to add comment