ARC 064 F-Rotated Palindromes

The meaning of problems

Asked how many of length \ (N \) and the character set of size \ (K \) strings by rotating palindromic sequence (the first character to the last) is obtained several times. \ (N, K \ le 10 ^ 9 \)

practice

Set \ (F_i \) is the minimum period \ (I \) number of palindromic sequence
has \ (f_i = K ^ {\ left \ lceil \ frac {i} {2} \ right \ rceil} - \ sum \ limits_ {j | i, j \ neq i} f_ {j} \)

If \ (I% N \ NEQ 0 \) , a palindromic sequence may be by nature, it is adjusted to a smaller \ (I \) or more \ (I \) , so here we only consider \ ( i | N \)

A cycle \ (I \) , may represent different nature \ (I \) strings
when the cycle \ (I \) is an even number, the shift (frac \ {i} {2 } \) \ also after a cycle as \ (i \) of the palindrome string, it will be counted twice

故:\[Ans=\sum\limits_{d|N,d~is~odd}f_d\cdot d+\frac{1}{2}\sum\limits_{d|N,d~is~even}f_d\cdot d\]

Direct violence is off

Guess you like

Origin www.cnblogs.com/Grice/p/12370490.html
064
arc