Posts

Showing posts with the label math

Solution of 'Divisible Sum Pairs' (HackerRank)

Hi all! Here's my solution to the problem 'Divisible Sum Pairs' from HackerRank. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int divisibleSumPairs ( int n , int k , vector < int > ar ) {     int cnt = 0 ;     for ( int i = 0 ; i < n ; i ++){         for ( int j = i + 1 ; j < n ; j ++){             if (( ar [ i ] + ar [ j ] )% k == 0 ) cnt ++;         }     }     return cnt ; } int32_t main () {     int n , k ;     cin >> n >> k ;     vector < int > num ;     for ( int i = 0 ; i < n ; i ++){         int x ;         cin >> x ;         num . pb ( x );     }     int res = divisibleS...

Solution of 'Breaking the Records' (HackerRank)

Hi all! Here's my solution to 'Breaking the Records' of HackerRank. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; vector < int > breakingRecords ( vector < int > scores ) {     int M = scores [ 0 ] , m = scores [ 0 ] , M_cnt = 0 , m_cnt = 0 ;     vector < int > temp ;     for ( int i = 0 ; i < scores . size (); i ++){         if ( scores [ i ] < m ){             m = scores [ i ] ;             m_cnt ++;         }         if ( scores [ i ] > M ){             M = scores [ i ] ;             M_cnt ++;         }     }     temp . pb ( M_cnt );     temp . pb ( m_cnt );   ...

Solution of 'Weird Palindrome Making' (Codechef November Challenge 2021 Div3)

Hey guys! Here's my solution to the problem 'Weird Palindrome Making' from Codechef November Challenge 2021 Div3. Comment any suggestions if you have. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int32_t main () {     int t ;     cin >> t ;     while ( t --){         int n ;         cin >> n ;         vector < int > odd ;         for ( int i = 0 ; i < n ; i ++){             int x ;             cin >> x ;             if ( x % 2 != 0 ) odd . push_back ( x );         }         int s = odd . size ();         cout << s / 2 << ' \n ' ;     }   ...

Solution of 'Equal Coins' (Codechef November Challenge 2021 Div 3)

Hola guys!! Here's my solution to the problem- 'Equal Coins' from Codechef November Challenge 2021 Div3. If you have any suggestions do comment. Happy Coding!! This question mainly tests your maths  skills. Question Link: https://www.codechef.com/NOV21C/problems/EQUALCOIN #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int32_t main () {     int t ;     cin >> t ;     while ( t --){         int x , y ;         cin >> x >> y ;         int sum = x + y * 2 ;         if ( sum != 0 ){             if ( x != 0 && sum % 2 == 0 ) cout << "YES" << ' \n ' ; // like 4 3             else if ( x == 0 && y % 2 == 0 ) cout << "YES" << ...

Solution of 'Face the Direction' (Codechef)

Hi guys! It's been a while. I am back with my solution of the question - ' Face the Direction' from Codechef Starters 11. Any suggestion for me is highly appreciated. Happy Coding! Question link: https://www.codechef.com/START11C/problems/FACEDIR #include   <bits/stdc++.h> #define   int  long long int using   namespace   std ; int32_t   main () {      int   t , x ;      cin >> t ;      while ( t --){          cin >> x ;          if ( x % 4 == 0 )  cout << "NORTH" << ' \n ' ;          else   if (( x - 1 )% 4 == 0 )  cout << "EAST" << ' \n ' ;          else   if (( x - 2 )% 4 == 0 )  cout << "SOUTH" << ' \n ' ;      ...

Solution of 'Three Friends' (Codeforces)

 Hello everyone! Here's my solution of the question-'Three Friends' from Codeforces. Any suggestion for me is highly appreciated. Happy Coding! question link: https://codeforces.com/problemset/problem/1272/A #include   <bits/stdc++.h> #define   long  long long int using   namespace   std ; int   main () {      int   q ;      cin >> q ;      int   d [ q ];      for ( int   m = 0 ; m < q ; m ++){          int   a , b , c , min = 1999999999 ;          cin >> a >> b >> c ;          int   a1 [ 3 ]={ a + 1 , a , a - 1 };          int   b1 [ 3 ]={ b + 1 , b , b - 1 };          int   c1 [ 3 ]={ c + 1 , c...