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

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define EX(a, b) (a = a ^ b, b = a ^ b, a = a ^ b)
  5. using namespace std;
  6.  
  7. int gcd(int a, int b)
  8. {
  9. return (b == ) ? a : gcd(b, a % b);
  10. }
  11.  
  12. class fenshu
  13. {
  14. public:
  15. int x, y;
  16.  
  17. fenshu friend operator + (fenshu n, fenshu m)
  18. {
  19. m.x *= n.y;
  20. n.x *= m.y;
  21. m.y *= n.y;
  22. n.y = m.y;
  23. n.x += m.x;
  24. int k = gcd(n.x, n.y);
  25. n.x /= k;
  26. n.y /= k;
  27. return n;
  28. }
  29.  
  30. fenshu friend operator / (int k, fenshu n)
  31. {
  32. EX(n.x, n.y);
  33. n.x *= k;
  34. return n;
  35. }
  36. };
  37.  
  38. fenshu ans_get(fenshu now)
  39. {
  40. if(now.x <= )
  41. {
  42. --now.y;
  43. return now;
  44. }
  45. else
  46. {
  47. EX(now.x, now.y); //小数倒置
  48.  
  49. fenshu s;
  50. s.x = now.x / now.y;
  51. s.y = ; //分离出来的整数
  52.  
  53. now.x = now.x % now.y;
  54. return / (s + ans_get(now));
  55. }//继续分离
  56. }
  57.  
  58. void solve()
  59. {
  60. int T;
  61. scanf("%d", &T);
  62. while(T--)
  63. {
  64. fenshu now, s;
  65. scanf("%d/%d", &now.x, &now.y);
  66. now = ans_get(now);
  67. printf("%d/%d\n", now.x, now.y);
  68. }
  69. }
  70.  
  71. int main()
  72. {
  73. solve();
  74. return ;
  75. }

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. JDBC中DAO+service设计思想

    一.DAO设计思想 a) Data access Object(数据访问对象):前人总结出的一种固定模式的设计思想. 高可读性. 高复用性. 高扩展性. b) JDBC代码实现的增删改查操作是有复用需 ...

  2. System.Timer.Timer的一个安全类

    class SafeTimer { private static System.Timers.Timer timer; public static Action DoWork; private sta ...

  3. VC++ ComBox下拉菜单看不到值

    在使用ComBox的时候,我是预先在属性页里面添加了数据的.但是在运行程序是发现,点击下拉时,一个值都看不到! 如图: 在这:http://blog.csdn.net/nma_123456/artic ...

  4. TZOJ 4651 zry和他的的灯泡们(lca)

    描述 zry有一个收集灯泡的习惯,他把灯泡的阴极都共地,阳极连成一颗树,这样的话,他只要在任意一个灯泡的阳极加上合适的电压,所有灯泡都能亮起来.不幸的是,有一对灯泡之间的阳极连线断掉了,这样的话,这颗 ...

  5. c++设计模式:单例模式

    1.设计思想: 单例模式,顾名思义,即一个类只有一个实例对象.C++一般的方法是将构造函数.拷贝构造函数以及赋值操作符函数声明为private级别,从而阻止用户实例化一个类.那么,如何才能获得该类的对 ...

  6. webapp-viewport 相关知识整理

    我们在开发移动设备的网站时,最常见的的一个动作就是把下面这个东西复制到我们的head标签中: <meta name="viewport" content="widt ...

  7. hibernate分页功能

    设置开始位置无效 设置终止位置是可以的 设置完之后,并没有分页 问题解决 https://blog.csdn.net/qq_39859824/article/details/77902488 http ...

  8. pytorch 常用问题解决

    1.RuntimeError: cuda runtime erorr (77): an illegal memory access was encountered at 在使用命令前面加上CUDA_L ...

  9. 未加星标 ajax三级联动的实现方法

    <div id="sanji"></div> 下面考虑的是要有省市区这三列,这三列用的是下拉列表,那么里面要用<option></opti ...

  10. 【python之路16】作业

    #!usr/bin/env python # -*- coding:utf-8 -*- # 数据库中原有 old_dict = { "#1": {'hostname': 'c1', ...