题意:就是一个蛋糕,被分成n或者m份。问最少动几刀。

看一下这个图,就知道公式了,n+m-gcd(n, m);

#include<cstdio>
#include<iostream>
using namespace std;
#define ll long long ll gcd(ll a, ll b){ return b == ? a : gcd(b, a%b); } int main()
{
ll n, m;
while (scanf("%lld%lld", &n, &m) != EOF)
{
if (n < m){ swap(n, m); }
printf("%lld\n", m + n - gcd(n, m));
}
}

C - Cake HDU - 1722 (数学)的更多相关文章

  1. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  2. hdu 1722 Cake 数学yy

    题链:http://acm.hdu.edu.cn/showproblem.php? pid=1722 Cake Time Limit: 1000/1000 MS (Java/Others)    Me ...

  3. HDU 1722 Cake (数论 gcd)(Java版)

    Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...

  4. HDU 1722 Cake

    #include<cstdio> int gcd(int m, int n) { ?n:gcd(n % m, m); } int main() { int m, n; while(scan ...

  5. HDU 1722 Cake 数学题

    #include<iostream> #include<stdio.h> #include<math.h> using namespace std; long lo ...

  6. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  7. *HDU 2451 数学

    Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  8. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  9. hdu 4506(数学,循环节+快速幂)

    小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

随机推荐

  1. html 颜色选择器 亲测,很好用

    @*以下 是测试html 颜色选择器的*@ @*<a href="#" mce_href="#" onclick="initColorPicke ...

  2. WebForm 【Repeater】展示数据

       在 Webform 数据展示中      界面层  : HTLM 业务逻辑层 :只能用 C#  Repeater    重复器  能够用来循环展示数据 具有5种模板  HeaderTemplat ...

  3. [android] androidPN开源项目介绍

    打开androidPN项目,会看到server和client两份代码 server部分 找到server的代码,开启服务,双击 bin/run.bat ,服务启动后监听127.0.0.1:7070端口 ...

  4. Web前端基础——jQuery(三)

    本文主要从以下几方面介绍jQuery应用中的内容: 1 jQuery 节点遍历2 jQuery 中的过滤器3 jQuery 属性操作4 jQuery Dom节点操作5 几个jQuery例子6 jQue ...

  5. java中import static和import的区别【转】

    转自:http://blog.csdn.net/ygc87/article/details/7371254

  6. Compiler showing 'pi' symbol on error

    Question: I was testing some code on Coliru, and I got a strange output. I went down the code and co ...

  7. Matlab forward Euler demo

    % forward Euler demo % take two steps in the solution of % dy/dt = y, y(0) = 1 % exact solution is y ...

  8. canvas处理压缩照片并回显:https://cengjingdeshuige.oss-cn-beijing.aliyuncs.com/20180512/cannovs%E5%AD%A6%E4%B9%A0.html

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. python 类函数,实例函数,静态函数

    一.实现方法 class Function(object): # 在类定义中定义变量 cls_variable = "class varibale" def __init__(se ...

  10. 图中最短路径的算法--dijiska算法C语言实现

    #include <stdio.h> #include <stdlib.h> #define ERROR_NO_MEM -1 /*内存不足的错误码*/ #define MAX_ ...