ප්‍රථමක සංඛ්‍යා

shenat

Well-known member
  • May 13, 2007
    58,428
    86,683
    113
    ආශ්චර්යමත් රටක
    එකෙනුත් එම සංඛ්යාවෙනුත් පමණක් බෙදෙන සංඛ්යා ප්‍රථමක සංඛ්යා නම් මේ.:sorry:

    ඒ කාලේ ගණන් පංති ඉවර උනේ රැ 8ට වගේ, මමයි අපේ පැත්තට යන තව කෙල්ලෝ 2නෙකුයි තමයි යන්නේ රෑ අම්බෝ එක කෙල්ලෙක්ගෙ කද :love: :baffled:

    turning point of the thread :rolleyes::rofl:

    ithin katawa kiyapanko :rofl:
     

    Error365!

    Well-known member
  • Jun 27, 2012
    13,009
    9,596
    113
    එක තැනක නෑ
    හා මොඩිෆයි කරලම එවපං. සෝස් කෝඩ් එකත් එවන්ඩ..
    හදිසියක් නෑ. හිමීට බලමු

    menna machan Java code eka :D

    Code:
    import 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<BigInteger, String> powLst = new LinkedHashMap<>();
            LinkedHashMap<BigInteger, 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(BigInteger.valueOf(i), BigInteger.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++) {
                        BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.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 (Map.Entry<BigInteger, String> entry : dupLst.entrySet()) {
                    BigInteger 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 BigInteger pow(BigInteger base, BigInteger exponent) {
            BigInteger result = BigInteger.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;
        }
    }
     
    • Like
    Reactions: 20_18

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    menna machan Java code eka :D

    Code:
    import 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<BigInteger, String> powLst = new LinkedHashMap<>();
            LinkedHashMap<BigInteger, 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(BigInteger.valueOf(i), BigInteger.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++) {
                        BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.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 (Map.Entry<BigInteger, String> entry : dupLst.entrySet()) {
                    BigInteger 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 BigInteger pow(BigInteger base, BigInteger exponent) {
            BigInteger result = BigInteger.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;
        }
    }

    හිමීට බලන්ඩෝන... :cool:
     

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    menna machan Java code eka :D

    Code:
    import 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<BigInteger, String> powLst = new LinkedHashMap<>();
            LinkedHashMap<BigInteger, 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(BigInteger.valueOf(i), BigInteger.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++) {
                        BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.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 (Map.Entry<BigInteger, String> entry : dupLst.entrySet()) {
                    BigInteger 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 BigInteger pow(BigInteger base, BigInteger exponent) {
            BigInteger result = BigInteger.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;
        }
    }

    මට 2^1 ඉඳල ආ‍වෙ නෑනෙ. 61^51 ඉඳල රිසල්ට් එක ආවෙ :( 97^99 න් ඉවරයි
     
    Last edited:

    Error365!

    Well-known member
  • Jun 27, 2012
    13,009
    9,596
    113
    එක තැනක නෑ
    මට 2^1 ඉඳල ආ‍වෙ නෑනෙ. 61^51 ඉඳල රිසල්ට් එක ආවෙ :( 97^99 න් ඉවරයි


    machan j = 1 karanna ethakota hari :)

    Code:
    import 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<BigInteger, String> powLst = new LinkedHashMap<>();
            LinkedHashMap<BigInteger, 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 ([COLOR="Red"]int j = 1[/COLOR]; j < power; j++) {
                            BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.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 ([COLOR="red"]int j = 1[/COLOR]; j < power; j++) {
                        BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.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 (Map.Entry<BigInteger, String> entry : dupLst.entrySet()) {
                    BigInteger 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 BigInteger pow(BigInteger base, BigInteger exponent) {
            BigInteger result = BigInteger.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;
        }
    }
     

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0

    LinkedHashMap kiyanne Data Structure ekak ban. Wisheshathwe thamai api data add karana anu piliwelatama data store wenawa. api data add karapu piliwelatama apita data read akranna puluwan :)

    :)

    අරක තාම හරිගියෙ නෑ මචං.. මම eqlipse දාගෙන ඉන්නෙ..
    Java SE 8.172 කිට් එක තියෙන්නෙ
    මටනං ලොකු දැනුමක් නෑ මේ ගැන
     

    Error365!

    Well-known member
  • Jun 27, 2012
    13,009
    9,596
    113
    එක තැනක නෑ
    :)

    අරක තාම හරිගියෙ නෑ මචං.. මම eqlipse දාගෙන ඉන්නෙ..
    Java SE 8.172 කිට් එක තියෙන්නෙ
    මටනං ලොකු දැනුමක් නෑ මේ ගැන


    awula mama hithanne umbe output eka pennana thana ida madi wage ban.

    max base eka 20k dapan, max power ekath 10k dapan. ita passe output eka balapanko.
     

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    හරි ගියා :cool:

    ටෙක්ස්ට් ෆයිල් එකකට ගන්නෙ කොහෙකාමද :confused:

    අනික තමා පවර් එක 100ට දුන්නම නැත්තං 50ට දුන්නම එකක් අඩු වෙලා ඉවර වෙන එක
    99න් ඉවර වෙනව
    නැත්තං 49න් ඉවර වෙනව
     
    Last edited:

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    හරි ගියා :cool:

    ටෙක්ස්ට් ෆයිල් එකකට ගන්නෙ කොහෙකාමද :confused:

    අනික තමා පවර් එක 100ට දුන්නම නැත්තං 50ට දුන්නම එකක් අඩු වෙලා ඉවර වෙන එක
    99න් ඉවර වෙනව
    නැත්තං 49න් ඉවර වෙනව

    for (int i = 2; i <= base; i++) {
    if (onlyPrimeNums) {
    if (pc.isPrime(i)) {
    for (int j = 1; j <= power; j++) {
    BigInteger pow = pc.pow(BigInteger.valueOf(i), BigInteger.valueOf(j));
    String nb = i + "^" + j;

    සමාන ලකුණ දැම්මම හරි ගියා ;)
     

    Error365!

    Well-known member
  • Jun 27, 2012
    13,009
    9,596
    113
    එක තැනක නෑ
    හරි ගියා :cool:

    ටෙක්ස්ට් ෆයිල් එකකට ගන්නෙ කොහෙකාමද :confused:

    අනික තමා පවර් එක 100ට දුන්නම නැත්තං 50ට දුන්නම එකක් අඩු වෙලා ඉවර වෙන එක
    99න් ඉවර වෙනව
    නැත්තං 49න් ඉවර වෙනව



    me link eke thiyana Question eke answers walin idea ekak aragena. code eka implement karanna try karanna dan thiyana code ekata

    kohen hari hira unoth kiyanna :)

    https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to-it-in-java
     

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    ප්‍රොග්‍රැමින් කෝඩ්ස් බ්ලා බ්ලා දන්නේ නෑ

    මාත් බං. දිරවන්නෙම නැති දෙයක්

    ඒත් මේ ළඟදි ජාවා පොඩ්ඩක් තේරුම් ගන්ඩ බැලුව :D
     

    20_18

    Member
    Feb 27, 2018
    1,297
    45
    0
    if (onlyPrimeNums) {

    ඔය කෑල්ල අයින් කරල බැලුව ඩුප්ලිකේට් අල්ලනවද නැද්ද කියල බලන්ඩ..

    වැඩ කොලා...

    2^2 overlap with 4^1
    2^4 overlap with 16^1
    2^6 overlap with 8^2
    2^8 overlap with 16^2
    2^10 overlap with 4^5
    2^12 overlap with 16^3
    2^14 overlap with 4^7
    2^16 overlap with 16^4
    2^18 overlap with 8^6
    2^20 overlap with 16^5
    2^3 overlap with 8^1
    2^9 overlap with 8^3
    2^15 overlap with 8^5
    4^12 overlap with 16^6
    4^15 overlap with 8^10
    4^18 overlap with 16^9
    3^2 overlap with 9^1
    3^4 overlap with 9^2
    3^6 overlap with 9^3
    3^8 overlap with 9^4
    3^10 overlap with 9^5
    3^12 overlap with 9^6
    3^14 overlap with 9^7
    3^16 overlap with 9^8
    3^18 overlap with 9^9
    3^20 overlap with 9^10
    4^14 overlap with 16^7
    4^16 overlap with 16^8
    8^16 overlap with 16^12