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 ...
随机推荐
- JAVA面试常见问题之Redis篇
Redis为单线程 1.Redis 有哪些数据类型 String 哈希 list set 有序set 2.Redis 内部结构 参考:https://www.cnblogs.com/chenpingz ...
- bzoj 1266 [AHOI2006] 上学路线
传送门 传说中的经典容斥+卢卡斯定理+中国剩余定理 题解传送门 //Achen #include<algorithm> #include<iostream> #include& ...
- nginx、php-fpm启动脚本
Nginx官方启动脚本 //service nginx stop|start|restart|reloadtouch /etc/init.d/nginx chmod nginxvi /etc/init ...
- 20190818 [ B ]-½
请看到这个蒟蒻博客的人注意一下. 这是简单的[ B ]场考试,如果需要[ A ]场题解请去神犇们的blog. [ B ]场不需要题解,恩? 太蒟蒻了QAQ 考试过程: 怀着我是蒟蒻我怕谁的心情. 首先 ...
- freopen() 函数的使用
当我们求解acm题目时,通常在设计好算法和程序后,要在调试环境(例如VC等)中运行程序,输入测试数据,当能得到正确运行结果后,才将程序提交到oj中.但由于调试往往不能一次成功,每次运行时,都要重新输入 ...
- Oil Deposits HDU - 1241 (dfs)
Oil Deposits HDU - 1241 The GeoSurvComp geologic survey company is responsible for detecting undergr ...
- 我悲惨的人生,该死的UPX壳,谁能救救我
一个程序,被加了UPX壳... 结果加壳的人把UPX脱壳的关键参数都给删除掉了,我现在连脱壳都脱不掉... 我从网上下载了UPX最新3.91版本的壳,复制了两个UPX.exe,本来互相加壳和脱壳都没 ...
- C#基础之特性
官网地址:https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/attributes/accessing- ...
- day37 09-Struts2和Hibernate整合环境搭建
<!-- 设置本地Session --> <property name="hibernate.current_session_context_class"> ...
- day36 03-Hibernate检索方式:排序、参数绑定、投影查询
排序之后是分页查询. 检索单个对象 还可以进行参数的绑定. HQL的参数绑定,按参数名称绑定或者是按参数位置绑定. 还可以用投影的操作,投影的操作是只查询这里面的某几个属性.只查询某一个属性,查询多个 ...