一个分数假如 3/5=1/(1+2/3)=1/(1+1/(1+1/2));

当分子出现1的时候,只要让分母减一。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define EX(a, b) (a = a ^ b, b = a ^ b, a = a ^ b)
using namespace std; int gcd(int a, int b)
{
return (b == ) ? a : gcd(b, a % b);
} class fenshu
{
public:
int x, y; fenshu friend operator + (fenshu n, fenshu m)
{
m.x *= n.y;
n.x *= m.y;
m.y *= n.y;
n.y = m.y;
n.x += m.x;
int k = gcd(n.x, n.y);
n.x /= k;
n.y /= k;
return n;
} fenshu friend operator / (int k, fenshu n)
{
EX(n.x, n.y);
n.x *= k;
return n;
}
}; fenshu ans_get(fenshu now)
{
if(now.x <= )
{
--now.y;
return now;
}
else
{
EX(now.x, now.y); //小数倒置 fenshu s;
s.x = now.x / now.y;
s.y = ; //分离出来的整数 now.x = now.x % now.y;
return / (s + ans_get(now));
}//继续分离
} void solve()
{
int T;
scanf("%d", &T);
while(T--)
{
fenshu now, s;
scanf("%d/%d", &now.x, &now.y);
now = ans_get(now);
printf("%d/%d\n", now.x, now.y);
}
} int main()
{
solve();
return ;
}

hdu4180 数论的更多相关文章

  1. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  2. NOIP2014 uoj20解方程 数论(同余)

    又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...

  3. 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)

    ~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...

  4. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  5. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  6. bzoj2219: 数论之神

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  8. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  9. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

随机推荐

  1. 一些hbase的shell查询语句

    华为bids(不想吐槽)种种原因只能用hbase shell查询,在此记录下自己探索的hbase shell 免得下次要用还得去找 scan 'ogg_sel_ioc_sv_product_name_ ...

  2. HDFS体系结构概述

  3. 移动端canvas刮刮乐

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta cont ...

  4. FileReader详解

    一.兼容性 从上图中可以看出IE7.8.9都不支持FileReader对象 二.作用 使用支持FileReader浏览器的用户可以通过一个file input选择一个图像文件将图片显示在页面中,而不用 ...

  5. web前端学习(四)JavaScript学习笔记部分(8)-- JavaScript瀑布流

    index.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  6. Hackerrank--Ashton and String(后缀数组)

    题目链接 Ashton appeared for a job interview and is asked the following question. Arrange all the distin ...

  7. Bootstrap常见的类

    一.标题 h1,h2,h3,h4,h5,h6

  8. fastjson map转json

    Map map = new HashMap(); map.put("name", "老三"); map.put("age", 12); St ...

  9. 神奇的CSS形状

    在StackOverflow上有这么一个问题,有位同学在 http://css-tricks.com/examples/ShapesOfCSS/ 找到一些使用CSS做的形状,其中一位同学对下面的这个形 ...

  10. 想真正了解JAVA设计模式看着一篇就够了。 详解+代码实例

    Java 设计模式   设计模式是对大家实际工作中写的各种代码进行高层次抽象的总结 设计模式分为 23 种经典的模式,根据用途我们又可以分为三大类.分别是创建型模式.结构型模式和行为型模式 列举几种设 ...