-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq.cpp
More file actions
52 lines (43 loc) · 965 Bytes
/
seq.cpp
File metadata and controls
52 lines (43 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
#include <cstdint>
#include <math.h>
int64_t ipow(int64_t base, int exp)
{
int64_t result = 1;
for (;;)
{
if (exp & 1)
result *= base;
exp >>= 1;
if (!exp)
break;
base *= base;
}
return result;
}
int64_t gcd(int64_t a, int64_t b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main(){
std::vector<int> v;
char c;
while (std::cin >> c)
{
v.push_back(((int)c - (int)('0')));
}
int64_t interm = 0;
for(int i=0; i < v.size(); i++){
interm += v[i]*((int64_t)1 << (i))*(ipow(3, v.size()-1-i));
}
int64_t a = (interm%((int64_t)1 << (v.size()-1)));
int64_t b = ((int64_t)1 << (v.size()-1));
int64_t gcf = gcd(a,b);
std::cout<<(interm/((int64_t)1 << (v.size()-1)));
if(a) std::cout<<' '<< a/gcf << '/' << b/gcf;
}