Gym

https://vjudge.net/problem/Gym-102058L

You are given a string s consisting of lowercase alphabets, and an integer k.

Make a new string t

by concatenating k copies of s. Determine whether t is a palindrome, e.g. is the same backward as forward.

Input

The first line contains a string s

consisting of lowercase alphabets. (1≤|s|≤250000)

The second line contains an integer k. (1≤k≤1018)

Output

If t is a palindrome, print YES. If not, print NO.

Examples

Input

abc
3

Output

NO

Input

abba
1

Output

YES

题意分析:

给出一个字符串s,问将k个s连接起来是不是回文串。

解题思路:

k的范围很大,所以不能直接求解,

仔细想想如果  s 是一个回文串,不管k是奇数还是偶数,都能保证连接起来是回文串;

相反,如果 s 不是回文串, 那么合成的字符串的开头的 s 和末尾的 s 肯定会有不相同的,

例如s="abs"不管k是多少,合成后的字符串肯定是    abs......abs,中间的不看,开头和末尾肯定不能构成回文串。

所以只要判断 s 是否为回文串即可。

#include <stdio.h>
#include <string.h>
#define N 250020
char str[N];
int Judge()
{
	int len=strlen(str);
	for(int i=0; i<=len/2; i++)
		if(str[i]!=str[len-i-1])
			return 0;
	return 1;
}
int main()
{
	int k;
	while(scanf("%s%d", str, &k)!=EOF)
	{
		if(Judge())
			printf("YES
");
		else
			printf("NO
");
	}
	return 0;
}
原文地址:https://www.cnblogs.com/zyq1758043090/p/11852517.html