Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cstring>
- #include <string>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <algorithm>
- #include <sstream>
- #include <cstdlib>
- #include <cmath>
- #include <random>
- #include <bitset>
- #include <cassert>
- #include <tuple>
- #include <list>
- #include <iterator>
- #include <unordered_set>
- #include <unordered_map>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- #define mp make_pair
- #define pb push_back
- #define mt make_tuple
- #define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
- #define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
- #define all(v) (v).begin(), (v).end()
- #define rall(v) (v).rbegin(), (v).rend()
- const int INF = 1791791791;
- const ll INFLL = 1791791791791791791ll;
- struct fraction {
- ll p, q;
- fraction() {
- p = 0;
- q = 1;
- }
- fraction(ll _p, ll _q) {
- //ll g = __gcd(_p, _q);
- ll g = 1;
- p = abs(_p / g);
- q = abs(_q / g);
- if ((_p < 0) ^ (_q < 0))
- p = -p;
- }
- fraction(ll x) {
- p = x;
- q = 1;
- }
- };
- fraction operator+(const fraction& f, const fraction& s) {
- return fraction(f.p * s.q + f.q * s.p, f.q * s.q);
- }
- fraction operator*(const fraction& f, const fraction& s) {
- return fraction(f.p * s.p, f.q * s.q);
- }
- bool operator==(const fraction& f, const fraction& s) {
- return f.q * s.p == f.p * s.q;
- }
- bool operator<(const fraction& f, const fraction& s) {
- return f.p * s.q < f.q * s.p;
- }
- istream& operator>>(istream& is, fraction& f) {
- is >> f.p >> f.q;
- return is;
- }
- ostream& operator<<(ostream& os, const fraction& f) {
- ll g = __gcd(f.p, f.q);
- os << f.p / g << "/" << f.q / g;
- return os;
- }
- template<class t>
- t fpow(t a, int n) {
- if (n == 0)
- return 1;
- else if (n & 1)
- return a * fpow(a, n ^ 1);
- else {
- t tmp = fpow(a, n >> 1);
- return tmp * tmp;
- }
- }
- const int max_pow = 10;
- ll p2[max_pow + 1];
- ll p3[max_pow + 1];
- int ify(char c) {
- if (c == '0')
- return 0;
- else if (c == '-')
- return -1;
- else
- return 1;
- }
- void solve() {
- char as; ll a1, a2; fraction a;
- char bs; ll b1, b2; fraction b;
- char cs; ll c1, c2; fraction c;
- char ds; ll d1, d2; fraction d;
- cin >> as >> a1 >> a2; a = ify(as) * fraction(p2[a1], p3[a2]); a1 = max(a1, -a1);
- cin >> bs >> b1 >> b2; b = ify(bs) * fraction(b1, p3[b2]);
- cin >> cs >> c1 >> c2; c = ify(cs) * fraction(c1, p3[c2]);
- cin >> ds >> d1 >> d2; d = ify(ds) * fraction(p2[d1], p3[d2]); d1 = max(d1, -d1);
- vector<fraction> vec;
- for (ll s = -1; s <= 1; s += 2) {
- forn(_p2, d1 + 1) {
- forn(q2, a1 + 1) {
- forn(_p3, max(max(a2, b2), max(c2, d2)) + 1) {
- forn(q3, max(max(a2, b2), max(c2, d2)) + 1) {
- ll p = s * p2[_p2] * p3[_p3];
- ll q = p2[q2] * p3[q3];
- fraction f(p, q);
- if (a * fpow(f, 3) + b * fpow(f, 2) + c * f + d == 0)
- vec.pb(f);
- }
- }
- }
- }
- }
- sort(all(vec));
- vec.resize(distance(vec.begin(), unique(all(vec))));
- cout << vec.size() << " ";
- for (auto f : vec)
- cout << f << " ";
- cout << endl;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- // Code here:
- forn(i, max_pow + 1) {
- p2[i] = fpow(2ll, i);
- p3[i] = fpow(3ll, i);
- }
- int t;
- cin >> t;
- forn(i, t)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement