Skip to main content

Posts

Showing posts from May, 2021

All Solution Code of CodeChef May Long Challenge 2021

competitve programming solution here...

solution code of An Interesting Sequence problem number-8 of may long challenge codechef

An Interesting Sequence Problem Solution Code: CodeChef #include   <bits/stdc++.h> using   namespace   std ; #define   endl   " \n " int   main () {     cin. tie ( 0 );      int  N  =   4 e 6   +   5 ;      int  phi[N], ans[N];      for  ( int  i  =   0 ; i  <  N; i ++ )     {         phi[i]  =  i;         ans[i]  =   0 ;     }      for  ( int  p  =   2 ; p  <  N; p ++ )     {          if  (phi[p]  ==  p)         {             phi[p]  =  p  -   1 ;              for  ( int  i  =   2   *  p; i  <  N; i  +=  p)             {                 phi[i]  =  (phi[i]  /  p)  *  (p  -   1 );             }         }     }      for  ( int  i  =   1 ; i  <  N; i ++ )     {         ans[i]  +=  i  -   1 ;          for  ( int  j  =   2   *  i; j  <  N; j  +=  i)         {             ans[j]  +=  i  *  (( 1   +  phi[j  /  i])  /   2 );         }     }      int  t;     cin  >>  t;      while  (t -- )     {          int  k;         cin  >>  k;         cout  <&l

solution code of Valid Paths problem number-7 of may long challenge codechef

 Valid Paths Problem Solution Code: CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   ll   long   long #define   f ( i ,  a ,  b )  for ( int  i = a; i < b; i ++ ) #define   mod   1000000007 #define   mk   make_pair #define   uniq ( v ) (v). erase ( unique ( all (v)), (v). end ()) #define   ff  first #define   ss  second #define   rf ( i ,  a ,  b )  for ( int  i = a;i >= b;i -- ) #define   sc ( a )  scanf ( " %lld " ,  & a) #define   pf   printf #define   sz ( a ) ( int )(a. size ()) #define   psf  push_front #define   ppf  pop_front #define   ppb  pop_back #define   pb  push_back #define   pq  priority_queue #define   all ( s ) s. begin (),s. end () #define   sp ( a )  setprecision (a) #define   rz  resize #define   ld   long   double #define   inf  ( ll ) 1 e 18 #define   ub  upper_bound #define   lb  lower_bound #define   bs  binary_search #define   eb  emplace_back const   double  pi  =   acos ( - 1 ); ll   binpow ( ll  

solution code of Tree House problem number-6 of may long challenge codechef

 Tree House Problem Solution Code: CodeChef Solution Code #pragma   GCC   optimize (" Ofast ", " unroll-loops ") #include   <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   double   long   double using   pii   =   pair < int ,  int >; template  < typename   T > using   Prior   =   std :: priority_queue < T ,  vector < T >,  greater < T >>; #define   X  first #define   Y  second #define   eb  emplace_back #define   ALL ( x )  begin (x),  end (x) #define   RALL ( x )  rbegin (x),  rend (x) #define   fastIO ()  ios_base ::sync_with_stdio, cin. tie ( 0 ) mt19937_64  rng( chrono :: steady_clock :: now (). time_since_epoch (). count ()); inline   int   getRand ( int   L ,  int   R ) {      if  ( L   >   R )          swap ( L ,  R );      return  ( int )(rng()  %  ( uint64_t )( R   -   L   +   1 )  +   L ); } template  < typename   T1 ,  typename   T2 > ostream   &operator <<( ostre

solution code of Modular Equation problem number-5 of may long challenge codechef

 Modular Equation Problem Code: CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   endl   " \n " int32_t   main () {      ios_base :: sync_with_stdio ( false );     cin. tie ( 0 );      int  t;cin >> t;      while (t -- )     {          int  n, m;cin >> n >> m;          int  count_of_pair  =   0 ;          vector < int >  modular_equation(n + 1 ,  1 );          for ( int  a  =   2 ;a <= n;a ++ )         {              int  x  =  m % a;             count_of_pair  +=  modular_equation [ x ] ;              for ( int  b  =  x;b <= n;b += a)             {                 modular_equation [ b ] ++ ;             }         }         cout << count_of_pair << endl ;     }      return   0 ; }

solution code of Tic Tac Toe problem number-4 of may long challenge codechef

 Tic Tac Toe Problem Solution Code:  CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   ll   long   long   int int   main () {      ll  t;     cin >> t;      while (t -- )     {          ll  cx  =   0 , co  = 0 , c_ =   0 ;          char  a[ 3 ][ 3 ];          for ( ll  i = 0 ;i < 3 ;i ++ )         {              for ( ll  j = 0 ;j < 3 ;j ++ )             {                 cin >> a[i][j];                  if (a[i][j] == 'X' )cx ++ ;                  if (a[i][j] == 'O' )co ++ ;                  if (a[i][j] == '_' )c_ ++ ;             }         }          ll  wx  =   0 , wo  =   0 ;          if (a[ 0 ][ 0 ]  ==   'X'   &&  a[ 1 ][ 0 ]  ==   'X'   &&  a[ 2 ][ 0 ]  ==   'X' )wx = 1 ;          if (a[ 0 ][ 1 ]  ==   'X'   &&  a[ 1 ][ 1 ]  ==   'X'   &&  a[ 2 ][ 1 ]  ==   'X' )wx = 1 ;          if (a[ 0 ][ 2 ]  ==   'X'   &

solution code of Xor Equality problem number-3 of may long challenge codechef

 Xor Equality Problem Solution Code: CodeChef Solution Code #include <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   endl   " \n " #define   m   1000000007 int   power ( int   x ,  unsigned   int   y ,  int   p ) {      int  res  =   1 ;       x   =   x   %   p ;      if  ( x   ==   0 )  return   0 ;      while  ( y   >   0 )     {          if  ( y   &   1 )             res  =  (res * x )  %   p ;          y   =   y >> 1 ;  // y = y/2          x   =  ( x * x )  %   p ;     }      return  res; } int32_t   main () {      int  t;cin >> t;      while (t -- )     {          int  n;cin >> n;         cout << power ( 2 , n - 1 ,  m ) << endl ;     }      return   0 ; }

solution code of Golf problem number-2 of may long challenge codechef

Golf Problem Code: LKDNGOLFSolvedSubmit Read problem statements in Bengali, Mandarin Chinese, Russian, and Vietnamese as well. It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hallway has N+2 tiles numbered from 0 to N+1 from left to right. There is a hole on tile number x. You hit the ball standing on tile 0. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are 0,k,2k,…, and so on until the ball passes tile N+1. If the ball doesn't enter the hole in the first trial, you try again but this time standing on the tile N+1. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are (N+1),(N+1−k),(N+1−2k),…, and so on until the ball passes tile 0. Find if the ball will enter the hole, either in its forward journey or backward journey. Note: The input and output of this problem are large, so prefer using fast input/output methods. Input The first line contains an integer T, the number of test

solution code of Solubility problem number-1 of may long challenge codechef

Solubility Problem Solution Code: CodeChef Solution Code #include   <bits/stdc++.h> using   namespace   std ; #define   int   long   long   int #define   endl   " \n " int32_t   main () {      int  t;     cin  >>  t;      while  (t -- )     {          int  p, x, y;         cin  >>  p  >>  x  >>  y;          int  ans  =   0 ;         ans  =  x  +  ( 100   -  p)  *  y;         ans  =  ans  *   10 ;         cout  <<  ans  <<   endl ;     }      return   0 ; }