Number of cycles formed by joining vertices of n sided polygon at the center | Java program for the above approach ; Function to calculate number of cycles ; BigInteger is used here if N = 10 ^ 9 then multiply will result into value greater than 10 ^ 18 ; BigInteger multiply function ; Return the final result ; Driver Code ; Given N ; Function Call
import java . util . * ; import java . math . * ; class GFG { static BigInteger findCycles ( int N ) { BigInteger res , finalResult ; long val = 2 * N - 1 ; String st = String . valueOf ( val ) ; BigInteger str = new BigInteger ( st ) ; String n1 = String . valueOf ( ( N - 1 ) ) ; String n2 = String . valueOf ( ( N - 2 ) ) ; BigInteger a = new BigInteger ( n1 ) ; BigInteger b = new BigInteger ( n2 ) ; res = a . multiply ( b ) ; finalResult = res . add ( str ) ; return finalResult ; } public static void main ( String args [ ] ) throws Exception { int N = 5 ; System . out . println ( findCycles ( N ) ) ; } }