Count Arithmetic Progressions having sum N and common difference equal to 1 | C ++ program for the above approach ; Function to count all possible AP series with common difference 1 and sum of elements equal to N ; Stores the count of AP series ; Traverse through all factors of 2 * N ; Check for the given conditions ; Increment count ; Print count - 1 ; Driver Code ; Given value of N ; Function call to count required number of AP series
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countAPs ( long long int N ) { long long int count = 0 ; for ( long long int i = 1 ; i * i <= 2 * N ; i ++ ) { long long int res = 2 * N ; if ( res % i == 0 ) { long long int op = res / i - i + 1 ; if ( op % 2 == 0 ) { count ++ ; } if ( i * i != res and ( i - res / i + 1 ) % 2 == 0 ) { count ++ ; } } } cout << count - 1 << " STRNEWLINE " ; } int main ( ) { long long int N = 963761198400 ; countAPs ( N ) ; }