Power Pokemon coding ninja solution

Problem:-

Note: Pokemons with different indices are considered different even if they have the same power level. Since the answer can be huge, print it modulo 10^9 + 7

Input Format:
``````First line of input contains a integer N, representing the number of pokemons.
Second line of input contains N space separated integers representing the power levels of the pokemons
``````
Constrains:
``````1 <= power.length <= 10^5
0 <= power[i] <= 22
``````
Sample Input 1:
``````5
1 3 5 7 9
``````
Sample Output 1:
``````4
``````
Explanation:
`````` The power pokemon couples formed are (1,3), (1,7), (3,5) and, (7,9).
Their respective sums are 4, 8, 8, and 16, all of which are powers of 2.
``````
Sample Input 2:
``````6
24 8 7 1 8 57
``````
Sample Output 2:
``5``

Solution:-

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int count=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int a=arr[i]+arr[j];

if(ceil(log2(a))==floor(log2(a)))
count++;
}
}
cout<<count;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int count=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int a=arr[i]+arr[j];

if(ceil(log2(a))==floor(log2(a)))
count++;
}
}
cout<<count;
}

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-