-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource1.cpp
58 lines (48 loc) · 968 Bytes
/
Source1.cpp
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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <array>
#include <stdio.h>
/*
vi a b k la z+
nen a<=x^2<=b => sqrt(a)<=x<=sqrt(b)
a<=y^3<=b => sqrt(a,3)<=y<=sqrt(b.3)
x chay tu sqrt a -> sqrt b
y chay tu sqrt a -> sqrt b
thua man dk cuoi cung
x^2-y^3 < k
*/
using namespace std;
int main() {
string line;
int count=0;
ifstream input("CAU1.INP");
ofstream output("CAU1.OUT");
long k = 0;
long a = 0;
long b = 0;
if (input.is_open()) {
getline(input, line);
sscanf_s(line.c_str(), "%d %d %d", &a,&b, &k);
for (int x = sqrt(a); x <= sqrt(b); x++)
{
for (int y = cbrt(a); y <= cbrt(b); y++)
{
if (abs(x*x - y * y*y) <= k )
{
cout << x<< " " << y << endl;
count++;
}
}
}
if (output.is_open())
{
output << count;
output.close();
}
input.close();
}
else cout << "Unable to open file";
return 0;
}