primes

Program to find prime numbers

吃可爱长大的小学妹 提交于 2019-11-25 19:17:32
I want to find the prime number between 0 and a long variable but I am not able to get any output. The program is using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication16 { class Program { void prime_num(long num) { bool isPrime = true; for (int i = 0; i <= num; i++) { for (int j = 2; j <= num; j++) { if (i != j && i % j == 0) { isPrime = false; break; } } if (isPrime) { Console.WriteLine ( "Prime:" + i ); } isPrime = true; } } static void Main(string[] args) { Program p = new Program(); p.prime_num (999999999999999L); Console

Checking if a number is a prime number in Python [duplicate]

折月煮酒 提交于 2019-11-25 19:02:12
This question already has an answer here: How to create the most compact mapping n → isprime(n) up to a limit N? 28 answers I have written the following code, which should check if the entered number is a prime number or not, but there is an issue i couldn't get through: def main(): n = input("Please enter a number:") is_prime(n) def is_prime(a): x = True for i in (2, a): while x: if a%i == 0: x = False else: x = True if x: print "prime" else: print "not prime" main() If the entered number is not a prime number, it displays "not prime", as it is supposed to, but if the number is a prime number