import
java.util.*;
import
java.lang.*;
class
GeeksforGeeks {
static
double
generateAP(
int
a,
int
d,
int
n,
int
AP[])
{
double
sum =
0
;
for
(
int
i =
1
; i <= n; i++) {
AP[i] = (a + (i -
1
) * d);
sum += (
double
)
1
/ (
double
)((a + (i -
1
) * d));
}
return
sum;
}
static
double
sumApproximation(
int
a,
int
d,
int
n)
{
return
Math.log((
2
* a + (
2
* n -
1
) * d) /
(
2
* a - d)) / d;
}
public
static
void
main(String args[])
{
int
a =
12
, d =
12
, n =
5
;
int
AP[] =
new
int
[n +
5
];
double
sum = generateAP(a, d, n, AP);
System.out.println(
"Harmonic Progression :"
);
for
(
int
i =
1
; i <= n; i++)
System.out.print(
"1/"
+ AP[i] +
" "
);
System.out.println();
String str =
""
;
str = str + sum;
str = str.substring(
0
,
4
);
System.out.println(
"Sum of the generated"
+
" harmonic progression : "
+ str);
sum = sumApproximation(a, d, n);
str =
""
;
str = str + sum;
str = str.substring(
0
,
4
);
System.out.println(
"Sum of the generated "
+
"harmonic progression using approximation : "
+ str);
}
}