Zbekiston respublikasi raqamli texnologiyalar vazirligi muhammad al-xorazmiy nomidagi



Yüklə 343,65 Kb.
səhifə7/7
tarix22.05.2023
ölçüsü343,65 Kb.
#119646
1   2   3   4   5   6   7
Loyiha ishi-kiber

Dastur kodi:
package pollard;
import java.math.BigDecimal;
import java.util.*;
public class GFG {
static BigDecimal gcd(BigDecimal a, BigDecimal b) {
int son = a.compareTo(BigDecimal.ZERO);
if (son == 0) {
return b;
}
return gcd(b.remainder(a), a);
}
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n == 2 || n == 3)
return true;
if (n % 2 == 0)
return false;
for (long i = 3; i * i <= n; i += 2)
if (n % i == 0)
return false;
return true;
}
static BigDecimal pollard(BigDecimal n) {
BigDecimal a = BigDecimal.valueOf(2);
BigDecimal i = BigDecimal.valueOf(2);
while (true) {
a = i.pow(a.intValue()).remainder(n);
a = a.add(n);
a = a.remainder(n);
BigDecimal d = gcd(a.subtract(BigDecimal.ONE), n);
int result = d.compareTo(BigDecimal.ONE);
if (result > 0) {
return d;
}
i = i.add(BigDecimal.ONE);
}
}
public static void main(String[] args) {
BigDecimal n = new BigDecimal("252245074561591631565758777960284564736623697
36904878100933060887887244216" +
"1202602816953288617390562942706430977943173089767599583674375492448088637729066809395210704895826474" +
"9843824491519970546839581757560659781401956291370756230639716876456768678729393339341703162051124451" +
"1892437239390863502308155450078419924080263102978663897532365363981719762081750552627197211945486141" +
"4422745287463223545226519029089034069500600943437226689881293180307292131690597624433577309833774346" + "99924583492845212206319390320703622866477008711013644010886555820367734996512061432529391693421190426715896428082690439073605633199475981032823");
BigDecimal num = n;
ArrayList ans = new ArrayList();
while (true) {
BigDecimal d = pollard(num);
ans.add(d);
long r = Long.valueOf(String.valueOf(num.divide(d)));
if (isPrime(r)) {
ans.add(BigDecimal.valueOf(r));
break;
} else
num = BigDecimal.valueOf(r);
}
System.out.println("Factors of " + n + " are ");
for (BigDecimal elem : ans)
System.out.println(elem + " ");
}}

Foydalanilgan adabiyotlar:



  1. https://e-library.namdu.uz/30%20%D0%A2%D0%B5%D1%85%D0%BD%D0%B8%D0%BA%D0%B0%20%D1%84%D0%B0%D0%BD%D0%BB%D0%B0%D1%80/Asbob%20va%20ularni%20elementlari%20sinash%20usullari.%20Gaibnazarov%20B.B.pdf

  2. https://tltaudit.ru/uz/heart-failure/razlozhenie-mnogochlenov-na-mnozhiteli-kak-razlozhit-na-mnozhiteli/

  3. https://en.wikipedia.org/wiki/Pollard%27s_p_%E2%88%92_1_algorithm#:~:text=Pollard's%20p%20%E2%88%92%201%20algorithm%20is,an%20algebraic%2Dgroup%20factorisation%20algorithm.

  4. https://www.geeksforgeeks.org/pollard-p-1-algorithm/

  5. https://www.codingninjas.com/codestudio/library/the-pollard-p-1-algorithm

Yüklə 343,65 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin