数学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. Qt html 界面混合编程

    Qt部分 项目文件.pro Qt += webenginewidgets webchannel 创建WebEngineView #include <QtWebEngineWidgets> ...

  2. 使用libuv实现生产者和消费者模式

    生产者和消费者模式(Consumer + Producer model) 用于把耗时操作(生产线程),分配给一个或者多个额外线程执行(消费线程),从而提高生产线程的响应速度(并发能力) 定义 type ...

  3. 【转】edittext设置点击链接

    I put some ClickableSpan in EditText, unfortunately, that spans are still not clickable. When I clic ...

  4. ffmpeg 错误码

    av_read_frame, av_write_frame等 经常会返回负值也即写数据包失败.不同的负值代表不同的含义,可以根据错误码定义,定位问题. #define EPERM 1 /* Opera ...

  5. 2064: 分裂 - BZOJ

    Description 背景: 和久必分,分久必和... 题目描述: 中国历史上上分分和和次数非常多..通读中国历史的WJMZBMR表示毫无压力. 同时经常搞OI的他把这个变成了一个数学模型. 假设中 ...

  6. PHP对XML文件操作之属性与方法讲解

    DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的子节点列表(只读) dataType 返回此节点的数据类型 Definit ...

  7. 【WCF--初入江湖】10 序列化和传输大型数据流

    10 序列化和传输大型数据流 1.前言 理解WCF的序列化形式 掌握DataContractSerializer序列化对象 比较性能 比较xmlSerializer序列化对象   大数据量传输设置 修 ...

  8. linux源代码阅读笔记 find_entry分析

    78 static struct buffer_head * find_entry(struct m_inode * dir, 79 const char * name, int namelen, s ...

  9. python库:fuzzywuzzy

    fuzzywuzzy 用于字符串匹配率.令牌匹配等 复制代码代码如下: from fuzzywuzzy import fuzzfuzz.ratio("Hit me with your bes ...

  10. POJ 1922

    #include<iostream>cheng da cai zi 11.21 //#include<stdio.h> #include<math.h> using ...