Codeforces Round #207 (Div. 1)B(数学)

数学so奇妙。。

这题肯定会有一个循环节 就是最小公倍数 

对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 using namespace std;
 8 #define N 1000100
 9 #define LL __int64
10 LL o[N][27];
11 char s1[N],s2[N];
12 LL gcd(int a,int b)
13 {
14     return b==0?a:gcd(b,a%b);
15 }
16 int main()
17 {
18     int i,k1,k2;
19     LL n,m;
20     scanf("%I64d%I64d",&n,&m);
21     cin>>s1>>s2;
22     k1 = strlen(s1);
23     k2 =strlen(s2);
24     LL d = gcd(k1,k2);
25     LL dd = (LL)k1*k2/d;
26     for(i = 0 ; i < k1 ; i++)
27     o[i%d][s1[i]-'a']++;
28     LL ans = 0;
29     for(i = 0 ; i < k2 ; i++)
30     ans+=o[i%d][s2[i]-'a'];
31     printf("%I64d\n",n*k1/dd*(dd-ans));
32     return 0;
33 }
View Code

 

posted @ 2013-10-19 12:00  _雨  阅读(263)  评论(0编辑  收藏  举报