Skip to content

Commit 9e8e817

Browse files
authored
Create Fractions(Partial).java
1 parent 169da77 commit 9e8e817

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
5+
class Codechef
6+
{
7+
static class FastReader
8+
{
9+
BufferedReader br;
10+
StringTokenizer st;
11+
12+
public FastReader()
13+
{
14+
br = new BufferedReader(new
15+
InputStreamReader(System.in));
16+
}
17+
18+
String next()
19+
{
20+
while (st == null || !st.hasMoreElements())
21+
{
22+
try
23+
{
24+
st = new StringTokenizer(br.readLine());
25+
}
26+
catch (IOException e)
27+
{
28+
e.printStackTrace();
29+
}
30+
}
31+
return st.nextToken();
32+
}
33+
34+
int nextInt()
35+
{
36+
return Integer.parseInt(next());
37+
}
38+
39+
40+
long nextLong()
41+
{
42+
return Long.parseLong(next());
43+
}
44+
45+
double nextDouble()
46+
{
47+
return Double.parseDouble(next());
48+
}
49+
50+
String nextLine()
51+
{
52+
String str = "";
53+
try
54+
{
55+
str = br.readLine();
56+
}
57+
catch (IOException e)
58+
{
59+
e.printStackTrace();
60+
}
61+
return str;
62+
}
63+
}
64+
static long __gcd(long a, long b)
65+
{
66+
if (b == 0)
67+
return a;
68+
return __gcd(b, a % b);
69+
70+
}
71+
public static void main(String[] args) throws java.lang.Exception{
72+
FastReader sc=new FastReader();
73+
int n=sc.nextInt();
74+
long n1,d1,res=0;
75+
for(int i=1;i<=n;i++) {
76+
for(int j=1;j<=n;j++) {
77+
n1=i*(j+1);
78+
d1=(i+1)*j;
79+
long d;
80+
d = __gcd(n1, d1);
81+
n1 = n1 / d;
82+
d1 = d1 / d;
83+
if(n1+1==d1) {
84+
res++;
85+
}
86+
}
87+
}
88+
System.out.println(res);
89+
}
90+
}

0 commit comments

Comments
 (0)