Please read the new rule regarding the restriction on the use of AI tools. ×

search_fool's blog

By search_fool, history, 4 years ago, In English

Hi community. I was giving test for some hiring test. The problem says given an array of size N and numbers from 1...M find number of ways to create the array with the followings restrictions. 1) a[i]≠a[i+1] 2) a[1]=a[N] (1 based index) Constraints 3<=N,M<=10^18 I was came up with formula M*(M-1)^(N-3)*(M-2) n>3 and M*(M-1) n==3 But it gave WA. Any suggestions. Thankyou in advance.

  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem link?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

if(n is odd) m*(m-1)^(n-2)%mod else m*(m-3)^(n-3)*(m-2)%mod