1 solutions

  • 0
    @ 2025-11-5 19:20:45

    Java :

    import java.util.*;
    
    public class Main{
        public static void main(String args[]){
            Scanner cin=new Scanner(System.in);
            int T=cin.nextInt();
            int a,b,r;
            while(T-->0){
                a=cin.nextInt();
                b=cin.nextInt();
                r=cin.nextInt();
                a+=b;
                if(a==0){
                    System.out.println(0);
                }
                else{
                    Stack<Integer>stack=new Stack<Integer>();
                    while(a!=0){
                        stack.push(a%r);
                        a/=r;
                    }
                    while(!stack.empty()){
                        System.out.print(stack.peek());
                        stack.pop();
                    }
                    System.out.println();
                }
           }
        }
    }
    
    • 1

    Information

    ID
    19270
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    (None)
    # Submissions
    0
    Accepted
    0
    Uploaded By