Sort by

recency

|

151 Discussions

|

  • + 0 comments
    string solve(int n) {
        long long res;
        queue<long long> q;
        set<long long> visited;
        q.push(9);
        while(!q.empty()){
            long long curr=q.front();
            if(curr%n==0){
                res=curr;
                break;
            }
            long long num1=curr*10;
            long long num2=curr*10+9;
            if(visited.find(num1)==visited.end()){
                q.push(num1);
                visited.insert(num1);
            }
            if(visited.find(num2)==visited.end()){
                q.push(num2);
                visited.insert(num2);
            }
            q.pop();
        }
        return to_string(res);
    }
    
  • + 0 comments

    def solve(n): lista = ["9"] while lista: a = lista.pop(0) if int(a) % n == 0: return a lista.append(a+"0") lista.append(a+"9")

  • + 0 comments

    Problems like these are great for sharpening problem-solving skills and understanding modular arithmetic concepts. Definitely an engaging exercise for coding enthusiasts! matchbox9 login

  • + 2 comments
    def solve(n):
        i = 0
        while True:
            i += 1
            x = int(bin(i)[2:]) * 9
            if x % n == 0:
                return str(x)
    
  • + 0 comments
    import java.math.BigInteger;
    import java.util.LinkedList;
    import java.util.Queue;
    import java.util.Scanner;
    
    public class Solution {
        static final int LIMIT = 500;
        static final int[] DIGITS = { 0, 9 };
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            int T = sc.nextInt();
            for (int tc = 0; tc < T; tc++) {
                int N = sc.nextInt();
                System.out.println(solve(N));
            }
    
            sc.close();
        }
    
        static BigInteger solve(int N) {
            boolean[] visited = new boolean[N];
    
            Queue<BigInteger> queue = new LinkedList<BigInteger>();
            queue.offer(BigInteger.valueOf(DIGITS[0]));
            while (true) {
                BigInteger head = queue.poll();
    
                for (int digit : DIGITS) {
                    if (head.equals(BigInteger.ZERO) && digit == 0) {
                        continue;
                    }
    
                    BigInteger next = head.multiply(BigInteger.TEN).add(BigInteger.valueOf(digit));
    
                    int remainder = next.mod(BigInteger.valueOf(N)).intValue();
                    if (remainder == 0) {
                        return next;
                    } else if (!visited[remainder]) {
                        visited[remainder] = true;
                        queue.offer(next);
                    }
                }
            }
        }
    }