Monday, 3 April 2017

Hackerrank solution for Divisible Sum Pairs in C++

Problem:- divisible pairs sum solution or Divisible Sum Pairs solution in C++ or Divisible Sum Pairs hacker rank solution in Java or Divisible Sum Pairs hacker rank solution c++ or Divisible Sum Pairs hacker rank solution c++ or Divisible Sum Pairs program in c or Divisible Sum Pairs solution in c or Divisible Sum Pairs hacker rank solution in python or Divisible Sum Pairs in java or Divisible Sum Pairs hacker rank solution in c or Hacker Rank Solution For Divisible Sum Pairs in C++ or Divisible Sum Pairs in C++ or Hacker Rank solution for Divisible Sum Pairs in C++.

Check This-
Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.

Logic:- Logic is very simple we have to take a number and compare is the first number is less than the second number then first number + second number divide by number input from user If the sum is divisible by number than increase the count or else for condition do not increase a count variable. See the explanation section with an example.

Explanation:- Let's take an example and with the help of an example try to understand the problem divisible pairs sum. Taking an input from the user and check if the number has divisible pairs sum or not.

User Input:- 6 is a size of an array and number 3 is for divide the pair sum.

6 3
1 3 2 6 1 2


So check the following conditions with all condition, here condition 1 is that first number should be less than the second number.

1 + 3 = 3
1 + 2 = 3
3 + 6 = 9
2 + 1 = 3
1 + 2 = 3


Only all above 5 conditions is true for given input and if we divide the sum pair than no reminder is occurring. Hence we get our answer, the answer is 5.

Also check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.

Copy the full solution or colored code and paste into the hacker rank editor and click to Run Code if the code runs successfully then click to Submit Code. Before pasting the code into the editor make sure you have chosen c++ editor in the top right drop down option.

Submit your solution here:- Click here

Tip:- Before copy the solution I recommended please read this full article, this will help you to build your own logic.


Solution:-

#include <bits/stdc++.h>
using namespace std;

int main()
{


int i, j ,k ,n, count=0;

cin >> n >> k;

vector<int> array(n);

for(i = 0; i < n ; i++)
{
cin >> array[i];
}

for(i = 0; i < n ; i++)
{
for(j = 0; j < n ; j++)
{
if(i < j)
{
if((array[i] + array[j]) % k == 0)
count++;
}
}
}
cout<<count;

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment