QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64769#2488. Diophantine EquationAs3b_team_f_masrWA 2ms3512kbC++2.0kb2022-11-25 15:35:092022-11-25 15:35:11

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 15:35:11]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3512kb
  • [2022-11-25 15:35:09]
  • Submitted

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define sc second
#define EPS 1e-9

const int N=1e7;
ll sqr(ll x)
{
    ll y=sqrtl(x);
    for(int i=0;i<2;i++)
    {
        if(y-i>0&&(y-i)*(y-i)==x)return y-i;
        if(y+i>0&&(y+i)*(y+i)==x)return y+i;
    }
    return 0;
}
int a[1000000],id;
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin>>t;
	while(t--)
    {
        ll n;
        cin>>n;
        vector<int> v;
        for(int i=1;i*i<=n;i++)
        {
            if(n%i==0)
            {
                v.push_back(i);
                v.push_back(n/i);
            }
        }
        unordered_map<int,int> mp;
        id=0;
sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++)
        {
            for(int j=0;j<v.size();j++)
            {
                if(1ll*v[i]*v[j]<=n&&!mp[v[i]*v[j]])
                {
                    a[id]=(1ll*v[i]*v[j]);
                    mp[v[i]*v[j]]++;
                    id++;
                }
else break;
            }
        }
        bool ok=0;
        ll ax,ay;
        for(int i=0;i<id;i++)
        {
            ll d=a[i];
            ll a=3,b=-3*d,c=d*d-n*n/d;
            ll sq=sqr(b*b-4*a*c);
            if(sq*sq==b*b-4*a*c)
            {
                ll x=-b+(ll)sq;
                if(x%6==0&&x>0)
                {
                    x/=6;
                    if(d-x>0)
                    {
                        if(x*x*x+(d-x)*(d-x)*(d-x)==n*n)
                        {
                            ok=1;
                            ax=x;
                            ay=d-x;
                            break;

                        }
                    }
                }
            }
        }

        if(ok)cout<<ax<<" "<<ay<<'\n';
        else cout<<"impossible\n";
    }

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3512kb

input:

4
1
2
3
4

output:

impossible
impossible
2 1
2 2

result:

ok correct (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3468kb

input:

1000
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101...

output:

impossible
impossible
2 1
2 2
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
8 4
impossible
impossible
impossible
impossible
impossible
im...

result:

wrong output format Expected integer, but "impossible" found (test case 98)