Strange Optimization

Accepted : 67   Submit : 289
Time Limit : 1000 MS   Memory Limit : 65536 KB

Strange Optimization

Bobo is facing a strange optimization problem. Given n,m , he is going to find a real number α such that f(12+α) is maximized, where f(t)=mini,j∈Z|in−jm+t| . Help him!

Note: It can be proved that the result is always rational.

Input

The input contains zero or more test cases and is terminated by end-of-file.

Each test case contains two integers n,m .

  • 1≤n,m≤109
  • The number of tests cases does not exceed 104 .

Output

For each case, output a fraction p/q which denotes the result.

Sample Input

1 1
1 2

Sample Output

1/2
1/4

Note

For the first sample, α=0 maximizes the function

//题意还是很好懂的,只要明白扩展欧几里得原理,这题很简单,i/n - j/m 可以化为 ( mi - nj ) / ( n * m )

因为 i,j 为整数所以等于  k*gcd(n,m)/(n*m)

所以 f(t)的最大值为 1 / ( Lcm(n,m)*2 )

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
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("%I64d%I64d",&n,&m)!=EOF)
{
LL p = gcd(n,m);
LL q = n*m*;
LL yue = gcd(p,q);
printf("%I64d/%I64d\n",p/yue,q/yue);
}
return ;
}

Strange Optimization(扩展欧几里得)的更多相关文章

  1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)

    http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...

  2. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...

  3. UVA 10090 Marbles 扩展欧几里得

    来源:http://www.cnblogs.com/zxhl/p/5106678.html 大致题意:给你n个球,给你两种盒子.第一种盒子每个盒子c1美元,可以恰好装n1个球:第二种盒子每个盒子c2元 ...

  4. POJ 1061 青蛙的约会 扩展欧几里得

    扩展欧几里得模板套一下就A了,不过要注意刚好整除的时候,代码中有注释 #include <iostream> #include <cstdio> #include <cs ...

  5. 【64测试20161112】【Catalan数】【数论】【扩展欧几里得】【逆】

    Problem: n个人(偶数)排队,排两行,每一行的身高依次递增,且第二行的人的身高大于对应的第一行的人,问有多少种方案.mod 1e9+9 Solution: 这道题由1,2,5,14 应该想到C ...

  6. poj 2891 扩展欧几里得迭代解同余方程组

    Reference: http://www.cnblogs.com/ka200812/archive/2011/09/02/2164404.html 之前说过中国剩余定理传统解法的条件是m[i]两两互 ...

  7. poj 2142 扩展欧几里得解ax+by=c

    原题实际上就是求方程a*x+b*y=d的一个特解,要求这个特解满足|x|+|y|最小 套模式+一点YY就行了 总结一下这类问题的解法: 对于方程ax+by=c 设tm=gcd(a,b) 先用扩展欧几里 ...

  8. poj 1061 扩展欧几里得解同余方程(求最小非负整数解)

    题目可以转化成求关于t的同余方程的最小非负数解: x+m*t≡y+n*t (mod L) 该方程又可以转化成: k*L+(n-m)*t=x-y 利用扩展欧几里得可以解决这个问题: eg:对于方程ax+ ...

  9. Codeforces7C 扩展欧几里得

    Line Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

随机推荐

  1. Linux学习笔记 (五)关机和重启命令

    一.关机命令 1.shutdown命令: shutdown [选项] [时间] 选项: -c:取消前一个关机命令 -h:关机 -r:重启 例:shutdown -r 05:30 &   //表 ...

  2. Spring使用经验之Listener综述

    Note:Spring使用版本是4.1.6.RELEASE 1. ContextLoaderListener最基本的SpringListener,加载Spring配置文件 配置名为contextCon ...

  3. linq-to-sql实现left join,group by,count

    linq-to-sql实现left join,group by,count 用linq-to-sql实现下面的sql语句: SELECT p.ParentId, COUNT(c.ChildId) FR ...

  4. 用Darwin开发RTSP级联server(拉模式转发)(附源代码)

    源代码下载地址:https://github.com/EasyDarwin orwww.easydarwin.org 在博客 在Darwin进行实时视频转发的两种模式 中,我们描写叙述了流媒体serv ...

  5. JS 自动计算HTML的font-size

    Rem尺寸解决方案,需要配合一些js动态设置<html>标签的font-size 和 viewport来配合 <script> (function(doc, win) { va ...

  6. 基于FPGA实现的高速串行交换模块实现方法研究

    基于FPGA实现的高速串行交换模块实现方法研究 https://wenku.baidu.com/view/9a3d501a227916888486d7ed.html

  7. char device

    /** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for f ...

  8. python学习之sys.getsizeof()

    sys.getsizeof() >>> help(sys.getsizeof)Help on built-in function getsizeof in module sys: g ...

  9. 李洪强-CALayer4-自定义层

    自定义层,其实就是在层上绘图,一共有2种方法,下面详细介绍一下. 一.自定义层的方法1 方法描述:创建一个CALayer的子类,然后覆盖drawInContext:方法,使用Quartz2D API进 ...

  10. C语言指针解说

    指针是C语言的一种数据类型.类似于C中的其它类型,比如int ,char 等.既然指针是一种类型,当我们定义该类型变量.该类型变量就称为指针变量. C中有了指针就有了指向. 指向:指针变量指向本身保存 ...