hdu4180 数论
一个分数假如 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 数论的更多相关文章
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- NOIP2014 uoj20解方程 数论(同余)
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...
- 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
- bzoj2219: 数论之神
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- hdu5072 Coprime (2014鞍山区域赛C题)(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
随机推荐
- JDBC中DAO+service设计思想
一.DAO设计思想 a) Data access Object(数据访问对象):前人总结出的一种固定模式的设计思想. 高可读性. 高复用性. 高扩展性. b) JDBC代码实现的增删改查操作是有复用需 ...
- System.Timer.Timer的一个安全类
class SafeTimer { private static System.Timers.Timer timer; public static Action DoWork; private sta ...
- VC++ ComBox下拉菜单看不到值
在使用ComBox的时候,我是预先在属性页里面添加了数据的.但是在运行程序是发现,点击下拉时,一个值都看不到! 如图: 在这:http://blog.csdn.net/nma_123456/artic ...
- TZOJ 4651 zry和他的的灯泡们(lca)
描述 zry有一个收集灯泡的习惯,他把灯泡的阴极都共地,阳极连成一颗树,这样的话,他只要在任意一个灯泡的阳极加上合适的电压,所有灯泡都能亮起来.不幸的是,有一对灯泡之间的阳极连线断掉了,这样的话,这颗 ...
- c++设计模式:单例模式
1.设计思想: 单例模式,顾名思义,即一个类只有一个实例对象.C++一般的方法是将构造函数.拷贝构造函数以及赋值操作符函数声明为private级别,从而阻止用户实例化一个类.那么,如何才能获得该类的对 ...
- webapp-viewport 相关知识整理
我们在开发移动设备的网站时,最常见的的一个动作就是把下面这个东西复制到我们的head标签中: <meta name="viewport" content="widt ...
- hibernate分页功能
设置开始位置无效 设置终止位置是可以的 设置完之后,并没有分页 问题解决 https://blog.csdn.net/qq_39859824/article/details/77902488 http ...
- pytorch 常用问题解决
1.RuntimeError: cuda runtime erorr (77): an illegal memory access was encountered at 在使用命令前面加上CUDA_L ...
- 未加星标 ajax三级联动的实现方法
<div id="sanji"></div> 下面考虑的是要有省市区这三列,这三列用的是下拉列表,那么里面要用<option></opti ...
- 【python之路16】作业
#!usr/bin/env python # -*- coding:utf-8 -*- # 数据库中原有 old_dict = { "#1": {'hostname': 'c1', ...