Dead Fraction
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 1258   Accepted: 379

Description

Mike is frantically scrambling to finish his thesis at the last minute. He needs to assemble all his research notes into vaguely coherent form in the next 3 days. Unfortunately, he notices that he had been extremely sloppy in his calculations. Whenever he needed to perform arithmetic, he just plugged it into a calculator and scribbled down as much of the answer as he felt was relevant. Whenever a repeating fraction was displayed, Mike simply reccorded the first few digits followed by "...". For instance, instead of "1/3" he might have written down "0.3333...". Unfortunately, his results require exact fractions! He doesn't have time to redo every calculation, so he needs you to write a program (and FAST!) to automatically deduce the original fractions. 
To make this tenable, he assumes that the original fraction is always the simplest one that produces the given sequence of digits; by simplest, he means the the one with smallest denominator. Also, he assumes that he did not neglect to write down important digits; no digit from the repeating portion of the decimal expansion was left unrecorded (even if this repeating portion was all zeroes).

Input

There are several test cases. For each test case there is one line of input of the form "0.dddd..." where dddd is a string of 1 to 9 digits, not all zero. A line containing 0 follows the last case.

Output

For each case, output the original fraction.

Sample Input

0.2...
0.20...
0.474612399...
0

Sample Output

2/9
1/5
1186531/2500000 题意:最后一位表示循环节,
 #include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> #define inf 1000000000
#define ll long long using namespace std;
char ch[];
ll ans1,ans2;
ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
void solve(ll a,ll b,ll c,ll d)
{
ll t1=a*d+b*c,t2=b*d,t=gcd(t1,t2);
t1/=t;t2/=t;
if(t2<ans2)ans2=t2,ans1=t1;
}
int main()
{
while(~scanf("%s",ch+))
{
ans2=(ll)1e60;
int n=strlen(ch+);
if(n==)break;
ll b=,a=;
for(int i=;i<=n-;i++)
a=a*+ch[i]-'',b*=;//三个.
ll t=b/*;
for(ll i=;i<=b;i*=,t=t+(b/i)*)
solve(a/i,b/i,a%i,t);
printf("%lld/%lld\n",ans1,ans2);
}
}
 
 

poj1930 数论的更多相关文章

  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. iosopendev配置

    Permission denied, please try again.Permission denied, please try again.Permission denied (publickey ...

  2. select *from where 和select *from jion on 语句的差别

    https://zhidao.baidu.com/question/541791438.html select 学号 a,成绩 a,姓名 b from 成绩表 a,学生表 b where a.学号=b ...

  3. 一个制作Xcode5插件的模板

    原Github地址:https://github.com/kattrali/Xcode5-Plugin-Template 安装将 本工成复制到~/Library/Developer/Xcode/Tem ...

  4. 第2节 azkaban调度:16、azkaban的介绍以及azkaban的soloserver的安装使用

    2. 工作流调度器azkaban 2.1 概述 azkaban官网: https://azkaban.github.io/ 2.1.1为什么需要工作流调度系统 l  一个完整的数据分析系统通常都是由大 ...

  5. springmvc导出excel(POI)

    /** * 导出excel表格 */ @RequestMapping(value = "/doExportData", method = {RequestMethod.POST, ...

  6. sqlite查看所有表名、判断表是否存在,字段名及字段信息

    sqlite查看所有表名.判断表是否存在,字段名及字段信息   sqlite查看所有表名及字段名查询table,type 段是'table',name段是table的名字, select name f ...

  7. Mac 输入法小技巧

    相信使用Mac的朋友第一次使用Mac首先要考虑的就是输入法的问题,现在越来越多的第三方输入法都开始支持Mac平台,是否有同学仍然执着于看似“不符”国人习惯用法的OS X自带拼音输入法呢?自带的拼音输入 ...

  8. 洛谷 P1214 等差数列

    https://www.luogu.org/problemnew/show/P1214 首先暴力枚举可以凑出来的数,对于每个数进行标记. 对于每一个等差数列,当我们知道前两个数后即可以得出整个序列,那 ...

  9. Java 的访问权限

    public>protected>默认(包访问权限)>private,因为protected除了可以被同一包访问,还可以被包外的子类所访问

  10. Xshell 配色方案 Ubuntu Solarized_Dark isayme

    前言 最近在用Ubuntu,发现它的配色方案挺好看的,所以查了下有没有大神做过Xshell的Ubuntu配色方案. 一看,果然还是有大佬做了这个的. 三套配色配置如下: 1. Ubuntu的Solar ...