-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCANTON.cpp
More file actions
48 lines (40 loc) · 690 Bytes
/
Copy pathCANTON.cpp
File metadata and controls
48 lines (40 loc) · 690 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
#include <iostream>
#include <math.h>
using namespace std;
void TERM(float x)
{
int i = int((sqrt(8*x+1)-1)/2);
int n = int(x-(i*(i+1)/2));
if(n == 0)
if(i%2 == 0)
cout<<"TERM "<<int(x)<<" IS "<<i<<"/"<<1;
else
cout<<"TERM "<<int(x)<<" IS "<<1<<"/"<<i;
else
{
n = (n > 0)?n:-n;
if(n == 1)
if(i%2 == 0)
cout<<"TERM "<<int(x)<<" IS "<<i+1<<"/"<<1;
else
cout<<"TERM "<<int(x)<<" IS "<<1<<"/"<<i+1;
else
if(i%2==0)
cout<<"TERM "<<int(x)<<" IS "<<i-n+2<<"/"<<n;
else
cout<<"TERM "<<int(x)<<" IS "<<n<<"/"<<i-n+2;
}
cout<<endl;
}
int main()
{
int t;
cin>>t;
while(t-- && t >= 0)
{
float x;
cin>>x;
TERM(x);
}
return 0;
}