QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#711191#2933. Sequinary NumeralsBackToSquare1AC ✓0ms3824kbC++202.2kb2024-11-05 01:36:442024-11-05 01:36:45

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 01:36:45]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3824kb
  • [2024-11-05 01:36:44]
  • 提交

answer

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
 
#define NN 2505
#define MM 5005
#define MOD 1000000007

struct frac{
    ll num = 0;
    ll denom = 1;

    frac operator+(frac a) {
        frac b;

        ll g = lcm(denom,a.denom);

        b.num = num*(g/denom) + a.num*(g/a.denom);
        b.denom = g;
        b.reduce();
        return b;
    }

    frac operator*(frac a) {
        frac b;
        b.num = num*a.num;
        b.denom = denom*a.denom;
        b.reduce();
        return b;
    }

    void reduce() {
        ll g = gcd(num,denom);

        if(g == 0) return;

        num /= g;
        denom /= g;
    }

    pair<ll,frac> proper() {
        frac a;
        ll b;
        b = num/denom;
        a.num = num%denom;
        a.denom = denom;
        a.reduce();
        return {b,a};
    }
};

ll binpow(ll a, ll n) {
    if(n == 0) return 1;
    if(n == 1) return a;
    ll b = binpow(a,n/2);
    if(n%2 == 0) return b*b;
    else return b*b*a;
}

void solve() {
    string s;
    cin >> s;
    ll k = s.length();
    frac ans;
    ans.num = 0;
    ans.denom = 1;
    for(ll i=0;i<k;i++) {
        ll d = (ll)(s[i] - '0');
        frac a;
        a.num = d;
        a.denom = 1;
        frac b;
        b.num = binpow(3,k-i-1);
        b.denom = binpow(2,k-i-1);
        ans = ans + a*b;
    }

    pair<ll,frac> c = ans.proper();
    if(c.V.num == 0) cout << c.K << '\n';
    else cout << c.K << ' ' << c.V.num << '/' << c.V.denom << '\n';
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(10);

    solve();

    return 0;

}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

2101

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

201

output:

5 1/2

result:

ok single line: '5 1/2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

2010211122112221202012

output:

16541 873801/1048576

result:

ok single line: '16541 873801/1048576'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

22222222222222222222222222222222

output:

1725755 572407425/1073741824

result:

ok single line: '1725755 572407425/1073741824'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

11111111111111111111111111111111

output:

862877 1646149249/2147483648

result:

ok single line: '862877 1646149249/2147483648'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

10000000000000000000000000000000

output:

287626 1264544299/2147483648

result:

ok single line: '287626 1264544299/2147483648'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

1

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2

output:

2

result:

ok single line: '2'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

10

output:

1 1/2

result:

ok single line: '1 1/2'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

11

output:

2 1/2

result:

ok single line: '2 1/2'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

12

output:

3 1/2

result:

ok single line: '3 1/2'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

20

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

21

output:

4

result:

ok single line: '4'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

22

output:

5

result:

ok single line: '5'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

201000101020120002210001022

output:

99539 7418955/33554432

result:

ok single line: '99539 7418955/33554432'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

21012020111221210112111012122211

output:

1056241 54451731/134217728

result:

ok single line: '1056241 54451731/134217728'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

121200

output:

25 19/32

result:

ok single line: '25 19/32'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

22010

output:

18 3/8

result:

ok single line: '18 3/8'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

1102121021020020112221202220100

output:

565301 930420511/1073741824

result:

ok single line: '565301 930420511/1073741824'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1022020000221011110121211

output:

47476 16343961/16777216

result:

ok single line: '47476 16343961/16777216'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

21100210121101

output:

698 349/2048

result:

ok single line: '698 349/2048'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

122110002

output:

97 61/256

result:

ok single line: '97 61/256'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

200200011120110

output:

806 6545/8192

result:

ok single line: '806 6545/8192'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

212020012222220200010110012112

output:

540506 7899177/8388608

result:

ok single line: '540506 7899177/8388608'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

21201001011

output:

222 19/64

result:

ok single line: '222 19/64'