Ordered Prime Signature | C # to find total number of divisors of a number , using ordered prime signature ; Finding primes upto entered number ; Finding primes by Sieve of Eratosthenes method ; If prime [ i ] is not changed , then it is prime ; Update all multiples of p ; Forming array of the prime numbers found ; Finding ordered prime signature of the number ; Map to store prime factors and the related exponents ; Declaring an iterator for map ; Finding prime factorization of the number ; Storing the prime factor and its exponent in map ; Storing the exponent in a List ; Sorting the stored exponents ; Printing the prime signature ; Finding total number of divisors of the number ; Adding one to each element present ; in ordered prime signature ; Multiplying the elements ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < int > primes ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } List < int > arr = new List < int > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] ) arr . Add ( i ) ; } return arr ; } static List < int > signature ( int n ) { List < int > r = primes ( n ) ; var factor = new Dictionary < int , int > ( ) ; List < int > sort_exp = new List < int > ( ) ; int k , t = n ; for ( int i = 0 ; i < r . Count ; i ++ ) { if ( n % r [ i ] == 0 ) { k = 0 ; while ( n % r [ i ] == 0 ) { n = n / r [ i ] ; k ++ ; } factor . Add ( r [ i ] , k ) ; sort_exp . Add ( k ) ; } } sort_exp . Sort ( ) ; Console . Write ( " ▁ The ▁ Ordered ▁ Prime ▁ Signature ▁ of ▁ " + t + " ▁ is ▁ : ▁ STRNEWLINE { ▁ " ) ; for ( int i = 0 ; i < sort_exp . Count ; i ++ ) { if ( i != sort_exp . Count - 1 ) Console . Write ( sort_exp [ i ] + " , ▁ " ) ; else Console . Write ( sort_exp [ i ] + " ▁ } STRNEWLINE " ) ; } return sort_exp ; } static void divisors ( int n ) { int f = 1 , l ; List < int > div = signature ( n ) ; l = div . Count ; for ( int i = 0 ; i < l ; i ++ ) { div [ i ] += 1 ; f *= div [ i ] ; } Console . Write ( " The ▁ total ▁ number ▁ of ▁ divisors ▁ of ▁ " + n + " ▁ is ▁ " + f + " STRNEWLINE " ) ; } static void Main ( ) { int n = 13 ; divisors ( n ) ; } }