-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva264.java
More file actions
57 lines (51 loc) · 1.36 KB
/
Uva264.java
File metadata and controls
57 lines (51 loc) · 1.36 KB
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
import java.util.*;
import java.io.*;
public class Uva264
{
static final int max = (int)1e7 ;
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
int num = 1 ;
int den = 1 ;
int [] numValues = new int[max];
int [] denValues = new int[max];
boolean status = false ;
for (int i = 0; i < max; i++) {
numValues[i] = num ;
denValues[i] = den ;
if(num==1&&den%2==1)
den++ ;
else if(den==1&&num%2==0)
num++ ;
else if(num==1&&den%2==0)
{
num++ ;
den-- ;
status = true ;
}
else if(den==1&&num%2==1)
{
num-- ;
den++ ;
status = false ;
}
else if(status)
{
num++ ; den-- ;
}
else if(!status)
{
num-- ; den++ ;
}
}
while(br.ready())
{
int x = Integer.parseInt(br.readLine());
pr.println("TERM "+x+" IS "+ numValues[x-1]+"/"+denValues[x-1] );
}
br.close();
pr.close();
}
}