Any its substring with length equal to k is a palindrome.
对于一个长度为n的串,任何它的长度为k的字串都是回文串。该串具有这样的性质:
如果k为偶数,母串所有字符都相等;aaaaaa
如果k为奇数,母串最多由两种字母组成;abababa
View Code
#include <iostream> #include <math.h> #define MOD 1000000007 using namespace std; long long ppow(long long x,long long y){ long long res=1; while(y--){ res=res*x%MOD; } return res; } int main(){ long long n,m,k; while(cin >> n >> m >> k){ if(k==1 || k>n){ cout << ppow(m,n) <<endl; } else if(k==n){ if(n%2==0){ cout << ppow(m,n/2) << endl; } else{ cout << ppow(m,n/2+1) <<endl; } } else{ if(k%2==0){ cout << m <<endl; } else{ cout << m*m <<endl; } } } return 0; }