Header Ads Widget

Alice and candies | Hackerearth solution

 Problem

Alice loves candies, so she went into a candy shop. Now the shopkeeper sells candies in packets and all packets contain an odd number of candies (1, 3, 5, 7.....). Alice wants exactly  candies but she also loves patterns so she decided to buy candies only if the number of candies in the packets is consecutive and distinct (means she cannot buy the same candy packet more than once) and the sum of all the candies in those packets is exactly .

Alice has an infinite amount of money and the shopkeeper also has infinite amount candy packets, so Alice wonders how many different sets of candy packets she can buy.

Find the number of different sets of candy packets that Alice can buy.

Input format

The first and the only line contains a single integer  (11000000000).

Output format

Print a single integer denoting the number of different sets of candy packets Alice can buy.

Sample Input
45
Sample Output
3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Exaplanation: Lola can buy 3 set of candy packets.

1. {5,7,9,11,13}

2.{13,15,17}

3.{45}

Code(C++):-

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. long long int n;
  5. long long int num;
  6. cin >> n;
  7. num = sqrt(n);
  8. long long int ans=0;
  9. for(long long int i=1;i<=num;i++){
  10. if(n % i == 0){
  11. if((( i%2 == 0)&&((n/i)%2 == 0))||(( i%2 != 0)&&((n/i)%2 != 0))){
  12. ans++;
  13. }
  14. }
  15. }
  16. cout << ans;
  17. return 0;
  18. }

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments