数学so奇妙。。

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

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

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define N 1000100
#define LL __int64
LL o[N][];
char s1[N],s2[N];
LL gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
int i,k1,k2;
LL n,m;
scanf("%I64d%I64d",&n,&m);
cin>>s1>>s2;
k1 = strlen(s1);
k2 =strlen(s2);
LL d = gcd(k1,k2);
LL dd = (LL)k1*k2/d;
for(i = ; i < k1 ; i++)
o[i%d][s1[i]-'a']++;
LL ans = ;
for(i = ; i < k2 ; i++)
ans+=o[i%d][s2[i]-'a'];
printf("%I64d\n",n*k1/dd*(dd-ans));
return ;
}

Codeforces Round #207 (Div. 1)B(数学)的更多相关文章

  1. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...

  2. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

  3. A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】

    题目: Little C loves number «3» very much. He loves all things about it. Now he has a positive integer ...

  4. Codeforces Round #549 (Div. 2) D 数学

    https://codeforces.com/contest/1143/problem/D 题意 有nk个城市,第1,k+1,2k+1,...,(n-1)k+1城市有餐厅,你每次能走l距离,a为起始位 ...

  5. Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)

    脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...

  6. Codeforces Round #207 (Div. 2) A. Group of Students

    #include <iostream> #include <vector> using namespace std; int main(){ ; cin >> m ...

  7. Codeforces Round #207 (Div. 2)C

    读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...

  8. Codeforces Round #207 (Div. 2)

    A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...

  9. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

随机推荐

  1. cocos3.2版本中的一些新特性

    1.设置屏幕分辨率的大小,需要手动添加: 2.去掉了所有CC开头的命名: 3.所有的单例(以前是采用shared开头方法),全部改为getInstance(); 4.cocos3.x以上的版本支持C+ ...

  2. 多线程学习之AsyncOperation实现线程间交互

    1.首先我们要实现如下图的效果:                                                          a.主线程A运行方法段1时创建子线程B b.然后子线 ...

  3. win7下Chrome有两个图标的解决方法

    摘抄自:http://www.sevenforums.com/browsers-mail/238406-windows-7-taskbar-creating-double-google-chrome- ...

  4. 使用XAMPP本地安装Wordpress博客

    最近一直在研究博客,也知道了大名鼎鼎的wordpress,因此也希望动手尝试一下,看看跟网站提供的博客有何区别. 第一个问题:能什么安装wordPress,能否用tocmat? 虽然问题很可笑,但是之 ...

  5. DevExpress控件使用系列--ASPxUploadControl(图片上传及预览)

        1.控件功能     列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例       2.1 ASPxImage                http: ...

  6. c#中获取服务器IP,客户端IP以及其它

    客户端ip:Request.ServerVariables.Get("Remote_Addr").ToString();客户端主机名:Request.ServerVariables ...

  7. pos机套现是怎么回事

    POS机是商家为了促进消费,向银行申请的刷卡机它的主要功能是转账就是通过客户的刷卡,把相对的金额转入商户的帐户银行会根据笔数或金额向商户收取手续费非法套现就是客户并未和商户产生贸易往来,单纯通过pos ...

  8. js收集的一些好的题型

    ①: var a = {x:1},b=a;var a = a.z = {Y:2}; 求a和b的值? ②:   var  w = (function a(){return '1'},function b ...

  9. 【贪心】Bzoj 2457:[BeiJing2011]双端队列

    2457: [BeiJing2011]双端队列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 209  Solved: 95[Submit][Stat ...

  10. [转载]JS中如何定义全局变量

    三种方法 1.在js的function外定义一个变量 var name='测试'; function XX(){        alert(name); } 2.不使用var,直接给定义变量,隐式的声 ...