第46屆ICPC亚洲区域赛(昆明热身赛)Sequinary Numerals

亮片数字

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64 位 IO 格式: %lld

题目描述

亮片数字是数字序列:
 d_n d_{n-1}\cdots d_1 d_0dndn−1​⋯d1​d0​
哪里d_ndn​是11或22而其他的都是0,10,1或22.
它表示有理数:d_0 + d1 *( 3/2) + d_2 *( 3/2)^ 2 + ... + d_n*( 3/2)^ nd0​+d1∗(3/1)+d2​∗(3/1)2+。。。+dn​∗(3/1)n
编写一个程序,该程序将亮片数字作为输入,并返回它表示为适当分数的数字。

输入描述:

The single line of input contains a sequinary numeral of no more than 3232 digits. 

输出描述:

 
    
Output consists of a single line. 
If the result is an integer, the output is the decimal integer. Otherwise, the output is NN a single space and K/MK/M where NN, KK and MM are decimal integers where K < MK<M and K/MK/M is in lowest terms (GCD(K, M)= 1GCD(K,M)=1).
示例1

输入

复制
2101

输出

复制
10
示例2

输入

复制
201

输出

复制
5 1/2

 

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    long long a=int(s[0]-'0'),b=1;
    for(int i=1;i<s.size();i++){
        a*=3;
        b*=2;
        long long g=__gcd(a, b);
        a/=g,b/=g;
        a+= b*(s[i]-'0');
    }
    if(b==1)
        cout << a;
    
    else
        cout<<a/b<<" "<<a%b<<'/'<<b; 
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

热血少年鸡小龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值