Sort by

recency

|

149 Discussions

|

  • + 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);
                    }
                }
            }
        }
    }
    
  • + 0 comments
    def solve(n):
        queue = deque(['9'])
        visited = set()
        
        while queue:
            current = queue.popleft()
            
            current_num = int(current)
            
            if current_num % n == 0:
                return current
                
            next_num1 = current + '0'
            next_num2 = current + '9'
            
            if next_num1 not in visited:
                queue.append(next_num1)
                visited.add(next_num1)
                
            if next_num2 not in visited:
                queue.append(next_num2)
                visited.add(next_num2)
    
  • + 0 comments

    The multiple sought belongs to the list: {9x1, 9x10, 9x11, 9x100, 9x101, ...} We notice that {1, 10, 11, 100, 101, ...} are the binary writings of the numbers {1, 2, 3, 4, 5, ...}

    def solve(n):
        i = 1
        res = 9*int(bin(i)[2:])
        while res % n:
            i = i + 1
            res = 9*int(bin(i)[2:])
        return str(res)