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. jsp+servlet实现文件上传

    上传(上传不能使用BaseServlet) 1. 上传对表单限制 * method="post" * enctype="multipart/form-data" ...

  2. android:numColumns="auto_fit" 失效问题

    GridView 设置此属性无效:android:numColumns="auto_fit" ,请确认已经设置过 android:columnWidth="*dp&quo ...

  3. 【Java】Java_15 打印九九乘法表

    使用For循环嵌套即可打印九九乘法表 以下是具体代码: /** * 打印九九乘法表 */ package com.oliver.test; public class TestMultiplicatio ...

  4. Loadrunner11之VuGen常用函数lr_user_data_point(一)

    Loadrunner11之VuGen常用函数lr_user_data_point(一) 上一篇 / 下一篇  2011-11-15 00:15:33 / 精华(1) / 置顶(1) / 个人分类:性能 ...

  5. 转:Window10下RabbitMQ安装图文教程

    一.erlang下载安装 1.下载 下载erlang,原因在于RabbitMQ服务端代码是使用并发式语言erlang编写的,下载地址:http://www.erlang.org/downloads,双 ...

  6. php的pear包管理

    1.安装:  $ sudo wget http://pear.php.net/go-pear.phar  $ sudo php go-pear.har 2.查看pear下安装的包:  $ pear l ...

  7. Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)

    Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university ...

  8. atitit.guice3 绑定方式打总结生成非单例对象toInstance toProvider区别 v2 pb29

    atitit.guice3 绑定方式打总结生成非单例对象toInstance toProvider区别 v2 pb29 1. 三 绑定方式的介绍1 2. To接口,链式绑定,用的最多的1 3. toC ...

  9. 基于Verilog的以2为底取对数函数log2(x)

    参考资料:xilinx AXI4 Stream Peripherals 源码 //*********************************************************** ...

  10. Android JNI和NDK学习(03)--动态方式实现JNI(转)

    本文转自:http://www.cnblogs.com/skywang12345/archive/2013/05/23/3092491.html 前面总结了静态实现JNI的方法,本文介绍如何动态实现J ...