Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Алгоритм определения простого числа
- """
- """
- def prime(number):
- if number < 2: return False
- currentNumber = 2
- while currentNumber**2 <= number:
- if number % currentNumber == 0:
- return False
- currentNumber += 1
- return True
- print(prime(13)) # вводим любое число
- """
- """
- Алгоритм, раскладывающий число n на простые множители
- !!Заметка вернет массив, в котором каждый простой множитель встречается столько раз, какова его степень в разложении n
- """
- """
- def factors(number):
- arrayOfSimpleNumbers = []
- currentNumber = 2
- while currentNumber**2 <= number:
- while number % currentNumber == 0:
- arrayOfSimpleNumbers.append(currentNumber)
- number //= currentNumber
- currentNumber += 1
- if number > 1:
- arrayOfSimpleNumbers.append(number)
- return arrayOfSimpleNumbers
- print(factors(14)) # вводим любое число
- """
- """
- Определения примерного кол-ва простых чисел в диапазоне от 2 до числа n
- """
- """
- import math
- number = 13 # вводим любое положительное целое число
- print(round(number / math.log(number)))
- """
- """
- Алгоритм определения точного кол-ва простых множителей числа n
- """
- """
- # Используем алгоритм, раскладывающий число n на простые множители
- def factors(number):
- arrayOfSimpleNumbers = []
- currentNumber = 2
- while currentNumber**2 <= number:
- while number % currentNumber == 0:
- arrayOfSimpleNumbers.append(currentNumber)
- number //= currentNumber
- currentNumber += 1
- if number > 1:
- arrayOfSimpleNumbers.append(number)
- return arrayOfSimpleNumbers
- def countOfPrimeFactors(number):
- arrayOfPrimeFactors = factors(number)
- arrayOfUsedNumber = []
- result = 1
- for i in arrayOfPrimeFactors:
- for j in arrayOfUsedNumber:
- if j == i: break
- else:
- result *= (arrayOfPrimeFactors.count(i) + 1)
- arrayOfUsedNumber.append(i)
- return result
- print(countOfPrimeFactors(12)) # вводим любой положительное целое число
- """
- """
- Решето Эратосфена - алгоритм, эффективно определяющий какие числа являются простыми в диапазоне от 2 до n
- """
- """
- def prime(*array):
- number = len(array[0]) - 1
- currentNumber = 2
- while currentNumber <= number:
- if array[0][currentNumber]:
- currentNumber += 1
- continue
- n = currentNumber * 2
- while n <= number:
- array[0][n] = 1
- n += currentNumber
- currentNumber += 1
- return array[0]
- array = [0 for i in range(13)] # указываем любое число, где 13, это число n. Индексы списка - числа
- print(prime(array))
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement