Codeforces Round #207 (Div. 1) B. Xenia and Hamming
Solution
Set lena to the length of string a, lenb to the length of string B, gcd, lcm, gcd for lena and lenb, lcm... You will find a coequal relationship. First, the lcm length is one cycle. Within one lcm length, each character of a is touched and only touched once with each character in the same coequal position of B, then it's easy. Find out the answer and try again with lcm ..
My code
//Hello. I'm Peter.#include
#include
#include
#include
#include
#include
#include
#include#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;typedef long double ld;typedef unsigned long long ull;#define peter cout< b; i--)#define repin(i, a, b) for (int i = a; i <= b; i++)#define depin(i, a, b) for (int i = a; i >= b; i--)#define pi 3.1415926535898#define eps 1e-6#define MOD 1000000007#define MAXN 1000010#define N#define Mll n,m,lena,lenb,d,l,sum;char a[MAXN],b[MAXN];int c[MAXN][26];int main(){ cin>>n>>m; scanf(%s%s,a,b); lena=len(a),lenb=len(b); d=__gcd(lena,lenb); l=lena/d*lenb; int t=0; rep(i,0,lena){ c[t++][a[i]-'a']+=1; if(t==d) t=0; } t=0; sum=l; rep(i,0,lenb){ sum-=c[t++][b[i]-'a']; if(t==d) t=0; } sum=(n*lena/l)*sum; cout<