text: Gijswijt 's Sequence | C # program to demonstrate Gijswijt 's sequence ; if the sequence is a ( 1 ) a ( 2 ) a ( 3 ) . . a ( n - 1 ) check if the sequence can be represented as x * ( y ^ k ) find the largest value of k ; count ; pattern of elements of size i from the end of sequence ; count ; extract the pattern in a reverse order ; check how many times the pattern is repeated ; if the element doesn 't match ; if the end of pattern is reached set value of k = 0 and increase the count ; return the max count ; print first n terms of Gijswijt 's sequence ; set the count ; stoes the element ; print the first n terms of the sequence ; push the element ; find the count for next number ; Driver code
code: using System ; using System . Collections . Generic ; class GFG { static int find_count ( List < int > ele ) { int count = 0 ; for ( int i = 0 ; i < ele . Count ; i ++ ) { List < int > p = new List < int > ( ) ; int c = 0 , j ; for ( j = ele . Count - 1 ; j >= ( ele . Count - 1 - i ) && j >= 0 ; j -- ) { p . Add ( ele [ j ] ) ; } j = ele . Count - 1 ; int k = 0 ; while ( j >= 0 ) { if ( ele [ j ] != p [ k ] ) { break ; } j -- ; k ++ ; if ( k == p . Count ) { c ++ ; k = 0 ; } } count = Math . Max ( count , c ) ; } return count ; } static void solve ( int n ) { int count = 1 ; List < int > ele = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( count + " , ▁ " ) ; ele . Add ( count ) ; count = find_count ( ele ) ; } } public static void Main ( String [ ] args ) { int n = 10 ; solve ( n ) ; } }