Count Arithmetic Progressions having sum N and common difference equal to 1 | Java 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
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void countAPs ( long N ) { long count = 0 ; for ( long i = 1 ; i * i <= 2 * N ; i ++ ) { long res = 2 * N ; if ( res % i == 0 ) { long op = res / i - i + 1 ; if ( op % 2 == 0 ) { count ++ ; } if ( i * i != res && ( i - res / i + 1 ) % 2 == 0 ) { count ++ ; } } } System . out . println ( count - 1 ) ; } public static void main ( String [ ] args ) { long N = 963761198400L ; countAPs ( N ) ; } }