import java.math.BigInteger;
import java.util.LinkedHashMap;
import java.util.Map;
LinkedHashMap එකෙන් ඔබ්ජෙක්ට් එකක් හදල තියෙනව මුලම. මම ඒක උඹ පෙන්නපුහමයි දැක්කෙ..
එතකොට අනිත් දෙකෙන් කොතනද හදල තියෙන්නෙ? මට හොයාගන්ඩ බෑනෙ
බිග් ඉන්ටිජර් ක්ලාස් එකයි, මැප් ක්ලාස් එකයි..
red color karala thiyanne Map Object eka
blue color karala thiyanne BigInteger Objects
umba BigInterger kiyala class eka use karanawa nam onama dekata aniwaryenma "import java.math.BigInteger;" me widihata import karaganna one.
Map class ekatath same
Code:
mport java.math.BigInteger;
import java.util.LinkedHashMap;
import java.util.Map;
public class powCalc {
public static void main(String[] args) {
powCalc pc = new powCalc();
LinkedHashMap<[COLOR="blue"]BigInteger[/COLOR], String> powLst = new LinkedHashMap<>();
LinkedHashMap<[COLOR="blue"]BigInteger[/COLOR], String> dupLst = new LinkedHashMap<>();
//variables (change this values as your requirement )
int base = 100;//max base
int power = 100;//max power
boolean onlyPrimeNums = true;//use only prime numbers or not
boolean showPow = true;//show or not output of power calc
for (int i = 2; i < base; i++) {
if (onlyPrimeNums) {
if (pc.isPrime(i)) {
for (int j = 2; j < power; j++) {
BigInteger pow = pc.pow([COLOR="blue"]BigInteger[/COLOR].valueOf(i), [COLOR="blue"]BigInteger[/COLOR].valueOf(j));
String nb = i + "^" + j;
if (showPow) {
System.out.println(nb + " = " + pow);
}
if (powLst.containsKey(pow)) {
dupLst.put(pow, nb);
} else {
powLst.put(pow, nb);
}
}
}
} else {
for (int j = 2; j < power; j++) {
[COLOR="blue"]BigInteger [/COLOR]pow = pc.pow([COLOR="blue"]BigInteger[/COLOR].valueOf(i), [COLOR="blue"]BigInteger[/COLOR].valueOf(j));
String nb = i + "^" + j;
if (showPow) {
System.out.println(nb + " = " + pow);
}
if (powLst.containsKey(pow)) {
dupLst.put(pow, nb);
} else {
powLst.put(pow, nb);
}
}
}
}
if (dupLst.size() > 0) {
for ([COLOR="Red"]Map[/COLOR].Entry<[COLOR="blue"]BigInteger[/COLOR], String> entry : dupLst.entrySet()) {
[COLOR="blue"]BigInteger [/COLOR]pow = entry.getKey();
String bas = entry.getValue();
System.out.println(powLst.get(pow) + " overlap with " + bas + "[" + pow + "]");
}
}else{
System.out.println("No value is overlapped");
}
}
private [COLOR="blue"]BigInteger [/COLOR]pow([COLOR="blue"]BigInteger [/COLOR]base, BigInteger exponent) {
BigInteger result = [COLOR="Blue"]BigInteger[/COLOR].ONE;
while (exponent.signum() > 0) {
if (exponent.testBit(0)) {
result = result.multiply(base);
}
base = base.multiply(base);
exponent = exponent.shiftRight(1);
}
return result;
}
private boolean isPrime(int n) {
if (n > 2 && n % 2 == 0) {
return false;
}
int top = (int) Math.sqrt(n) + 1;
for (int i = 3; i < top; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
}



