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 ...
随机推荐
- python时间处理,datetime中的strftime/strptime
python中datetime模块非常好用,提供了日期格式和字符串格式相互转化的函数strftime/strptime 1.由日期格式转化为字符串格式的函数为: datetime.datetime.s ...
- poj2752
poj2752找所有的前缀等于后缀,那就是找所有前缀等于后缀的前缀,递归再用栈存一下 #include<iostream> #include<cstdio> #include& ...
- Hackerrank--Team Formation
题目链接 For an upcoming programming contest, Roy is forming some teams from the n students of his unive ...
- 关于网上大量对Vue双向绑定的错误理解
对于Vue的双向绑定,现在基本是个前端都听说过,面试官也喜欢问这个问题.但对于Vue双向绑定的原理,掘金.博客园和segmentfault等技术社区充斥着大量的错误文章.这些文章的题目基本样子如下 “ ...
- uva 11300 分金币(利用绝对值加和进行求出最小值)
//qq 767039957 welcome #include<cstdio> #include<algorithm> #include<vector> #incl ...
- Leetcode24.Swap Nodes in Pairs两两交换链表中的节点
给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 示例: 给定 1->2->3->4, 你应该返回 2->1->4->3. 说明: 你的算法只能使用常数的 ...
- 【JZOJ3623】【SDOI2014】数表(table) 树状数组+离线+莫比乌斯反演
题面 100 \[ Ans=\sum_{i=1}^n\sum_{j=1}^mg(gcd(i,j)) \] 其中, \[ g(d)=\sum_{i|d}i \] 我们注意到\(gcd(i,j)\)最多有 ...
- C++学习笔记(2)---2.5 C++函数编译原理和成员函数的实现
转载自:http://c.biancheng.NET/cpp/biancheng/view/2996.html点击打开链接 从上节的例子可以看出,对象的内存模型中只保留了成员变量,除此之外没有任何其他 ...
- DirectX11笔记(六)--Direct3D渲染2--VERTEX BUFFER
原文:DirectX11笔记(六)--Direct3D渲染2--VERTEX BUFFER 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u0103 ...
- 麻烦把JS的事件环给我安排一下
上次大家跟我吃饱喝足又撸了一遍PromiseA+,想必大家肯定满脑子想的都是西瓜可乐...... 什么西瓜可乐!明明是Promise! 呃,清醒一下,今天大家搬个小板凳,听我说说JS中比较有意思的事件 ...