Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class u11689
- {
- public static void main(String [] args)
- {
- Scanner key=new Scanner(System.in);
- int t=key.nextInt();
- while(t>0)
- {
- int r=0;int sum=0;
- int e=key.nextInt();
- int f=key.nextInt();
- int c=key.nextInt();
- int u=e+f;
- while(u>0)
- {
- u=u/c;
- r=r+u%c;
- sum=sum+u;
- if(r==c)
- {
- r=r/c;
- sum=sum+r;
- }
- if(u==1)
- {
- break;
- }
- }
- System.out.println(sum);
- t--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement