Advertisement
Guest User

u

a guest
Sep 23rd, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class u11689
  3. {
  4. public static void main(String [] args)
  5. {
  6. Scanner key=new Scanner(System.in);
  7. int t=key.nextInt();
  8. while(t>0)
  9. {
  10. int r=0;int sum=0;
  11. int e=key.nextInt();
  12. int f=key.nextInt();
  13. int c=key.nextInt();
  14. int u=e+f;
  15. while(u>0)
  16. {
  17. u=u/c;
  18. r=r+u%c;
  19. sum=sum+u;
  20. if(r==c)
  21. {
  22. r=r/c;
  23. sum=sum+r;
  24. }
  25. if(u==1)
  26. {
  27. break;
  28. }
  29. }
  30. System.out.println(sum);
  31. t--;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement