题目:
题意:
给出
n
∗
m
n*m
n∗m大小的一整块蛋糕,每小块为
1
∗
1
1*1
1∗1
从对角线切去,一共能雨露均沾到几块小蛋糕
分析:
直接莽规律,开始手玩了近
1
h
1h
1h结果一直看不来什么
后来找了个画图网站,再试了下立马发现了
.
.
.
...
...
对于
2
∗
3
2*3
2∗3和
3
∗
2
3*2
3∗2,我们发现本质其实是一样的,为了方便计算,我们将较小的作为第一项
2
∗
3
2*3
2∗3比
2
∗
2
2*2
2∗2多了
2
2
2
3
∗
4
3*4
3∗4比
3
∗
3
3*3
3∗3多了
3
3
3
4
∗
5
4*5
4∗5比
4
∗
4
4*4
4∗4多了
4
4
4
以此类推,我们可以得到一个简单的规律,而
3
∗
5
3*5
3∗5只比
3
∗
4
3*4
3∗4多
1
1
1,其他的也不尽相同
但如此我们计算
6
∗
9
6*9
6∗9时得到的便是
14
14
14,实际应该是
12
12
12
我们再次画图,发现可以将
6
∗
9
6*9
6∗9分成三个
2
∗
3
2*3
2∗3,如此一来先计算
2
∗
3
2*3
2∗3的答案,最后转化得到
6
∗
9
6*9
6∗9的答案
代码:
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#define LL long long
#define LZX Mu
using namespace std;
inline LL read() {
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
int main()
{
int n=read(),m=read(),king=__gcd(n,m);
if(n==m) return !printf("%d",n);
if(n>m) swap(n,m);
n/=king;m/=king;
int ans=n<<1;
for(int i=n+2;i<=m;i++,ans++);
cout<<ans*king;
return 0;
}