Skip to main content

Posts

Showing posts from February, 2021

How to append char to end of string in C++ || Best way to append char to end of string

 How to append char to end of string in C++ || Best way to append char to end of string- There are 2 ways mention below to append char to the end of string in c++. But do you know which one is the best way?  Let's see Method -1  += operator we can use += use to append char at the end of the string but by using this method it makes a copy of the initial string and take O(length of the string ) time to make a copy of a string. Method 2- Push back method by using this method we do not create any copy of original string we only put char to the and of the string so the time complexity of this function is o(1). Obviously, push back is a better method to append char at the end of the string.

Prime Game February long challenge 2021 solution with code and explanation

 Prime Game February long challenge 2021 solution with code and explanation  - Problem statement - Chef and Divyam are playing a game with the following rules: First, an integer  X ! X !  is written on a board. Chef and Divyam alternate turns; Chef plays first. In each move, the current player should choose a positive integer  D D  which is divisible by up to  Y Y  distinct primes and does not exceed the integer currently written on the board. Note that  1 1  is not a prime. D D  is then subtracted from the integer on the board, i.e. if the integer written on the board before this move was  A A , it is erased and replaced by  A − D A − D . When one player writes  0 0  on the board, the game ends and this player wins. Given  X X  and  Y Y , determine the winner of the game. Input The first line of the input contains a single integer  T T  denoting the number of test cases. The description of  T T  test cases follows. The first and only line of each test case contains two space-sepa