import
java.util.*;
public
class
GCDOfArmstrongNumbers {
public
static
boolean
isArmstrong(
int
num)
{
int
originalNum = num;
int
sum =
0
;
int
numDigits = String.valueOf(num).length();
while
(num >
0
) {
int
digit = num %
10
;
sum += Math.pow(digit, numDigits);
num /=
10
;
}
return
sum == originalNum;
}
public
static
int
gcd(
int
a,
int
b)
{
if
(b ==
0
) {
return
a;
}
return
gcd(b, a % b);
}
public
static
void
gcdProduct(
int
rangeStart,
int
rangeEnd)
{
int
smallestArmstrong = Integer.MAX_VALUE;
int
largestArmstrong = Integer.MIN_VALUE;
for
(
int
i = rangeStart; i <= rangeEnd; i++) {
if
(isArmstrong(i)) {
smallestArmstrong
= Math.min(smallestArmstrong, i);
largestArmstrong
= Math.max(largestArmstrong, i);
}
}
if
(smallestArmstrong == Integer.MAX_VALUE
|| largestArmstrong == Integer.MIN_VALUE) {
System.out.println();
}
else
{
int
gcdResult
= gcd(smallestArmstrong, largestArmstrong);
System.out.println(gcdResult);
}
}
public
static
void
main(String[] args)
{
int
rangeStart =
100
;
int
rangeEnd =
10000
;
gcdProduct(rangeStart, rangeEnd);
}
}