primes

Datetime does not show up

旧巷老猫 提交于 2020-01-11 14:06:12
问题 I am trying to get timestamp to show- I have tried the onCreate query in different ways and also tried to to have addTime as a value in addPrime . Nothing seems to work. My intention is for the app to show previous primes and the time that they were found. The intention for the app is for the user to be able to close/kill the app and resume counting from last found prime number when restarting the app, if you have any hints how also this would be possible I would be grateful. This is the

Datetime does not show up

戏子无情 提交于 2020-01-11 14:05:40
问题 I am trying to get timestamp to show- I have tried the onCreate query in different ways and also tried to to have addTime as a value in addPrime . Nothing seems to work. My intention is for the app to show previous primes and the time that they were found. The intention for the app is for the user to be able to close/kill the app and resume counting from last found prime number when restarting the app, if you have any hints how also this would be possible I would be grateful. This is the

Datetime does not show up

我与影子孤独终老i 提交于 2020-01-11 14:05:10
问题 I am trying to get timestamp to show- I have tried the onCreate query in different ways and also tried to to have addTime as a value in addPrime . Nothing seems to work. My intention is for the app to show previous primes and the time that they were found. The intention for the app is for the user to be able to close/kill the app and resume counting from last found prime number when restarting the app, if you have any hints how also this would be possible I would be grateful. This is the

program to print series of prime numbers using java

ⅰ亾dé卋堺 提交于 2020-01-11 11:45:50
问题 This code is to print the series of prime number up to given limit but when I am trying to execute this,it goes into infinite loop. import java.io.*; class a { public static void main(String s[]) throws IOException { int count=1; String st; System.out.println("how many prime no. do you want"); BufferedReader obj= new BufferedReader (new InputStreamReader (System.in)); st=obj.readLine(); int n=Integer.parseInt(st); while(count!=n) { int num=2; for(int i=2;i<num;i++) { if(num%i==0) { count++;

Prime Numbers in Java - Algorithms

空扰寡人 提交于 2020-01-11 10:49:29
问题 I have started learning to code in Java and decided I would use the Project Euler site to give me little tasks to try and complete with each bit of new coding I learn. So I came across Problem 3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I thought about the problem and researched many different theories about prime numbers and how they can be found via various different calculations (Sieve of Eratosthenes being an example)

Prime number generator crashes from memory error if there are too many numbers in array

£可爱£侵袭症+ 提交于 2020-01-07 02:29:24
问题 I have a prime number generator, I was curious to see how small and how fast I could get a prime number generator to be based on optimizations and such: from math import sqrt def p(n): if n < 2: return [] s = [True]*(((n/2)-1+n%2)+1) for i in range(int(sqrt(n)) >> 1): if not s[i]: continue for j in range( (i**i+(3*i) << 1) + 3, ((n/2)-1+n%2), (i<<1)+3): s[j] = False q = [2]; q.extend([(i<<1) + 3 for i in range(((n/2)-1+n%2)) if s[i]]); return len(q), q print p(input()) The generator works

Prime factors in C

走远了吗. 提交于 2020-01-05 07:11:20
问题 I came across this effective program for printing all the prime factors of a given number: # include <stdio.h> # include <math.h> // A function to print all prime factors of a given number n void primeFactors(int n) { // Print the number of 2s that divide n while (n%2 == 0) { printf("%d ", 2); n = n/2; } // n must be odd at this point. So we can skip // one element (Note i = i +2) for (int i = 3; i <= sqrt(n); i = i+2) { // While i divides n, print i and divide n while (n%i == 0) { printf("%d

Scheme prime numbers

萝らか妹 提交于 2020-01-05 03:03:33
问题 this is possibly much of an elementary question, but I'm having trouble with a procedure I have to write in Scheme. The procedure should return all the prime numbers less or equal to N (N is from input). (define (isPrimeHelper x k) (if (= x k) #t (if (= (remainder x k) 0) #f (isPrimeHelper x (+ k 1))))) (define ( isPrime x ) (cond (( = x 1 ) #t) (( = x 2 ) #t) ( else (isPrimeHelper x 2 ) ))) (define (printPrimesUpTo n) (define result '()) (define (helper x) (if (= x (+ 1 n)) result (if

Dynamic Sieve Algorithms for Prime Generation

拟墨画扇 提交于 2020-01-04 06:54:06
问题 I'm implementing the Sieve of Eratosthenes, for an explanation of this see http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. However I would like to adapt it to generate M primes, not the primes 1 through N. My method of doing this is simply to create a large enough N such that all M primes are contained in this range. Does anyone have any good heuristics for modeling the growth of primes? In case you wish to post code snippets I am implementing this in Java and C++. 回答1: To generate M

How to find a number as a sum of prime numbers?

北城余情 提交于 2020-01-04 03:16:11
问题 Lets see we want to find all numbers between 1 to 1000 which are represented as a sum of two prime numbers. e.g 8 = 3+5, 24 = 13+11 Now this can be done in O(n^2) by iterating through the list of prime numbers between 1 to 1000. Is there anyway of doing the same thing in less than O(n^2).Is there a method for doing this in linear time ? 回答1: Make an array p of 1000 booleans. Set p[i] to true if i is prime, and false otherwise. Then the O(N^2) algorithm becomes easy: go through numbers k 1