Prime number generator
Hello everyone,
I try to create prime number and so I create a RSAPrivateCrtKey with the aim to get the p prime via the getP() method. So I wrote
static RSAPrivateCrtKey prime = = (RSAPrivateCrtKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_CRT_PRIVATE, KeyBuilder.LENGTH_RSA_512, false);
// I don't know how to initialize the RSAPrivateCrtKey
prime.getP(tab, (short)0);Somebody know how to initialize the key? and so, I can retrieve the prime.
Thanks,
Charles
you may want to use genKeyPair method of KeyPair class...
Similar Messages
-
Prime number generator code, problems
hi, im having problems making a program to generate the prime numbers from 1 to 100. any help appreciated. here is the code i did so far.
public class primeNumbers {
public static void main(String args[]) {
for(x=1;x<101;x++)
prime=1;
if (prime/prime==1) prime++;
else System.out.println(" ");
System.out.println(" prime is " + prime);
}{color:red}CROSS POSTED{color}
[http://forum.java.sun.com/thread.jspa?threadID=5299159]
Cross posting is rude.
db -
Report based on Serial Number generated in the Production Order
Hi,
I wish to generate a Customized report, which shall include the total consumption based on Sales Order/Line Item/Serial Number/Production Order matching the Serial Number generated in the Production Order where in we can get the required data.
Need your help and suggestions in creating this report..
Thanks in advance..
Ashok Vardhan
Edited by: Ashok T Vardhan on Jan 19, 2012 11:38 AMHello Tman,
This is a slightly tricky question. The reason being, the report options like the report path etc, are set before you see the serial number prompt when you run your UUT. There might be other ways of getting around this, but a quick solution would be modifying the process model.
I modified the PreUUT callback to set the report options. I passed the reportOptions as a parameter to this sequence. In the PreUUT sequence, I set the following fields:
Parameters.ReportOptions.GeneratePath=False
Parameters.ReportOptions.ReportFilePath= "c:\\"+ Locals.SerialNumber +"\\report.xml"
I hope this would give you an idea.
SijinK -
Array size limitations... and prime number programs.
What are they? I am an ameteur programmer who wrote an extremely efficient prime finding program, if i do say so myself. The program doesnt find high primes, just prime numbers from 1-1,000,000,000 so far. Thats one version, the next version i use is faster, but because it uses an ArrayList, it can only do the primes 1-10,000,000. I am trying to work the programs up to primes with 50 or more digits, but ArrayList runs out of space, Integer is too small, I dont quite know how to switch all my code to be compatable with BigIntegers, and I cannot find a limit to arrays. I guess that I could find big primes if a) Integer was bigger, b)I tried, but what i wanted to do, because the second program is way more effecient, is to use an array to store primes instead of an ArrayList. The only problem? Arrays cannot be appended, so I need to know the limit in size for an array... So far, from my tests, I have found the limit to be somewhere around, 15,380,277. The only problem with this is that every time i compile, i can use a different number. So I would like it if a) somone could tell me the limit to an array's size, b) ideas for programs that can find primes with 50 or more digits, c) Down below is the code, could someone tell me how to convert it to BigIntegers?
private void primeFinder1root(int beg, int end){
int tmp = 0;
int counter = 0;
int counter2 = 2;
boolean flag;
for(int n = 3; n < end; n+=2){
if(n%5!=0){
flag = true;
for(int d = 3; d <= Math.sqrt(n) && flag; d+=2){
counter++;
if(n%d == 0)
flag = false;
if(flag){
System.out.println(n);
counter2++;
tmp = n;
if(counter2%100000 == 0)
System.out.println(n);
System.out.println();
System.out.println("The program looped " + counter + " times. There were " + counter2 + " primes found. "
+ tmp + " was the last prime found.");
}That is the first progam that does not use an ArrayList, but is still extremely effecient, it only looped 1,744,118,556 times to find the primes 1-100,000,000 which seems like a lot, but it truely isn't. I realize that by using counters and printing, I am slowing the program down immensly, but i am fine with that.
public void primeFinder(){
boolean flag;
int tmp = 0;
int tmp2 = 0;
int counter = 0;
primes.add(2);
for(int n = 3; n < end; n+=2){
if(n%5!=0){
flag = true;
for(int i = 0; i < primes.size()/2 && ((Integer)primes.get(i)).intValue() <= Math.sqrt(n) && flag; i++){
tmp = ((Integer)primes.get(i)).intValue();
if(n%tmp == 0)
flag = false;
counter ++;
if(flag && n!=1){
System.out.println(n);
primes.add(n);
tmp2 = n;
if(primes.size() % 100000 == 0)
System.out.println(n);
primes.add(0, 1);
System.out.println(counter + " " + primes.size() + " " + tmp2);
}This is the code that stores all the primes it finds in an ArrayList, and then compares all numbers to the ArrayList of primes. This is extremely more effecient than the first, looping only 278,097, 308 times to find the primes 1-10,000,000 (the other looped 868,772,491 times). I used 10,000,000 as my example because this program cannot go to 100,000,000 because there are 5,761,455 primes and the ArrayList can only hold ~4,000,000 objects. Because of this ~4,000,000 object limitation on the ArrayList I have set my sites on the Array. This is the reason why I want to know the limitations of an Array if you could please tell me. If you could also, I would like help making my code compatable with BigIntegers as well.
Well, sorry for the very long post, but thank you if you answer it and took the time to read it.
Dumber_ChildI too was in the quest to develop the most efficient prime number code few years ago when I was a student.
Here is a more fine tuned version for your code
public static long findPrimes(int max, ArrayList out){
long count=0;
FastList primes = new FastList((int)Math.sqrt(max));
primes.add(2);
for (int i=3; i<=max; i+=2)
int al_size = primes.size();
double sqrt = Math.sqrt(i);
boolean prime_flag =true;
boolean loop_flag = prime_flag;
for (int j=0; j<al_size && loop_flag; j++)
int val = primes.get(j);
if (i%val == 0)
loop_flag = prime_flag = false;
else if (val > sqrt)
loop_flag = false;
count++;
if (prime_flag)
primes.add(i);
primes.addToArrayList(out);
return count;
Following a data structure to store the prime numbers while processing
Since this holds first number of primes in an array instead of in an ArrayList
the get will work much faster and for those elements the casting is not required
static class FastList
ArrayList list = new ArrayList();
int cache[];
int pointer = 0;
int fastAreaSize;
public FastList(int fastAreaSize){
cache = new int[fastAreaSize];
this.fastAreaSize = fastAreaSize;
public void add(int i){
if (pointer < fastAreaSize)
cache[pointer] = i;
list.add(new Integer(i));
pointer++;
public int size(){
return pointer;
public int get(int i){
if (i<fastAreaSize)
return cache;
else
return((Integer)list.get(i)).intValue();
public void addToArrayList(ArrayList al){
for (int i=0; i<pointer; i++)
if (i<fastAreaSize)
al.add(new Integer(cache[i]));
else
al.add(list.get(i));
When running in my pc
above code detected primes within range 0-10000000 in 281809517 iterations within 6.718secs
while your original code did the same in 278097308 iterations within 13.687 secs.
By the way i removed the check for '5' thats why my code does more iterations.
Notice that I have relocated code like Math.sqrt and ((Integer).....).intValue() to reduce the re calculating the same thing. That saved a lot of time. -
Has anyone created a lottery number generator within Labview & if so can I have a copy please?
I would like to study the program of a lottery number generator for Labview if anyone has created or knows where I can get this.
Wow, my vi is close to yours, but I have a different problem: I set mine up to generate a door prize-winning "powerball," but my issue is how can I get the array to show each number in a different cell in the array, rather than in every cell at the same time. I think I need an array constant somewhere, but with a while loop in the for loop, I can't seem to come up with the desired operation.
Here's a copy of my vi and a pic of the "spaghetti"
Also, I'm running on my version 9 student edition.
Thanks for any help.
Attachments:
My Powerball.vi 53 KB
Lotto code.JPG 117 KB -
Prime Number Formula in PL/SQL
Hi Friends,
Oracle 11.2.0.1
Windows XP Prof.
Two questions, but almost same nature :
1.Is there any formula by which we can get the total count of prime numbers for a given number; i mean suppose I says 10, it means it should return 3; i.e. there are total 3 prime number between 1-10.
Here I can use a function which will say me that a given number is prime or not, and i will loop up to that given number. But, this is not actually a Formula, its kind of calculation. I am just looking a fixed matehematical formula for it; if it exists or not. If exists, then how that PL/SQL block will looks like.
2.Suppose I wish to get 50 prime numbers (starting from 1), then what will be the 50th prime number, i mean upto which highest number my calculation will expanded.
If possible, this should also be based upon a fixed formula.
Not actually a business requirement, but my nephew (student of class 9th) asked me these questions. I said him, neither I am student of maths nor that much knowledgeable in PL/SQL.
I asked him, why you are looking these formulas. He said, just these questions raised in my mind and curious to know that is there a fixed formula in maths exists or not. I said him, "Have you asked from your Maths teacher?" He said "Yes, sir told me, that there is no such a fixed mathematical formula, because there is no fixed gap in their ranges, what you says?"
I thought, let me write here.
Regards
Girish SharmaUsing SQL & MODEL. Not the fastest solution, but calculates first 1000 prime numbers in 5 seconds:
VARIABLE cnt NUMBER
EXEC :cnt := 1000;
SELECT prime
FROM dual
CONNECT BY LEVEL < 3
MODEL
DIMENSION BY(
level i
MEASURES(
level prime,
0 probe,
0 is_prime,
2 prime_cnt
RULES ITERATE(1e9) UNTIL(prime_cnt[1] >= :cnt)
probe[any] = 2 * iteration_number + 3,
is_prime[1] = case
when min(mod(probe,prime))[i between 2 and probe[1] / 2] = 0
then 0
else 1
end,
prime_cnt[1] = prime_cnt[1] + is_prime[1],
probe[1] = case
when is_prime[1] = 0
then 1
else probe[1]
end,
prime[probe[1]] = probe[1]
PRIME
1
2
3
5
7
11
13
17
19
23
29
PRIME
31
37
41
43
47
53
59
61
67
71
73
PRIME
79
83
89
97
101
103
107
109
113
127
131
PRIME
137
139
149
151
157
163
167
173
179
181
191
PRIME
193
197
199
211
223
227
229
233
239
241
251
PRIME
257
263
269
271
277
281
283
293
307
311
313
PRIME
317
331
337
347
349
353
359
367
373
379
383
PRIME
389
397
401
409
419
421
431
433
439
443
449
PRIME
457
461
463
467
479
487
491
499
503
509
521
PRIME
523
541
547
557
563
569
571
577
587
593
599
PRIME
601
607
613
617
619
631
641
643
647
653
659
PRIME
661
673
677
683
691
701
709
719
727
733
739
PRIME
743
751
757
761
769
773
787
797
809
811
821
PRIME
823
827
829
839
853
857
859
863
877
881
883
PRIME
887
907
911
919
929
937
941
947
953
967
971
PRIME
977
983
991
997
1009
1013
1019
1021
1031
1033
1039
PRIME
1049
1051
1061
1063
1069
1087
1091
1093
1097
1103
1109
PRIME
1117
1123
1129
1151
1153
1163
1171
1181
1187
1193
1201
PRIME
1213
1217
1223
1229
1231
1237
1249
1259
1277
1279
1283
PRIME
1289
1291
1297
1301
1303
1307
1319
1321
1327
1361
1367
PRIME
1373
1381
1399
1409
1423
1427
1429
1433
1439
1447
1451
PRIME
1453
1459
1471
1481
1483
1487
1489
1493
1499
1511
1523
PRIME
1531
1543
1549
1553
1559
1567
1571
1579
1583
1597
1601
PRIME
1607
1609
1613
1619
1621
1627
1637
1657
1663
1667
1669
PRIME
1693
1697
1699
1709
1721
1723
1733
1741
1747
1753
1759
PRIME
1777
1783
1787
1789
1801
1811
1823
1831
1847
1861
1867
PRIME
1871
1873
1877
1879
1889
1901
1907
1913
1931
1933
1949
PRIME
1951
1973
1979
1987
1993
1997
1999
2003
2011
2017
2027
PRIME
2029
2039
2053
2063
2069
2081
2083
2087
2089
2099
2111
PRIME
2113
2129
2131
2137
2141
2143
2153
2161
2179
2203
2207
PRIME
2213
2221
2237
2239
2243
2251
2267
2269
2273
2281
2287
PRIME
2293
2297
2309
2311
2333
2339
2341
2347
2351
2357
2371
PRIME
2377
2381
2383
2389
2393
2399
2411
2417
2423
2437
2441
PRIME
2447
2459
2467
2473
2477
2503
2521
2531
2539
2543
2549
PRIME
2551
2557
2579
2591
2593
2609
2617
2621
2633
2647
2657
PRIME
2659
2663
2671
2677
2683
2687
2689
2693
2699
2707
2711
PRIME
2713
2719
2729
2731
2741
2749
2753
2767
2777
2789
2791
PRIME
2797
2801
2803
2819
2833
2837
2843
2851
2857
2861
2879
PRIME
2887
2897
2903
2909
2917
2927
2939
2953
2957
2963
2969
PRIME
2971
2999
3001
3011
3019
3023
3037
3041
3049
3061
3067
PRIME
3079
3083
3089
3109
3119
3121
3137
3163
3167
3169
3181
PRIME
3187
3191
3203
3209
3217
3221
3229
3251
3253
3257
3259
PRIME
3271
3299
3301
3307
3313
3319
3323
3329
3331
3343
3347
PRIME
3359
3361
3371
3373
3389
3391
3407
3413
3433
3449
3457
PRIME
3461
3463
3467
3469
3491
3499
3511
3517
3527
3529
3533
PRIME
3539
3541
3547
3557
3559
3571
3581
3583
3593
3607
3613
PRIME
3617
3623
3631
3637
3643
3659
3671
3673
3677
3691
3697
PRIME
3701
3709
3719
3727
3733
3739
3761
3767
3769
3779
3793
PRIME
3797
3803
3821
3823
3833
3847
3851
3853
3863
3877
3881
PRIME
3889
3907
3911
3917
3919
3923
3929
3931
3943
3947
3967
PRIME
3989
4001
4003
4007
4013
4019
4021
4027
4049
4051
4057
PRIME
4073
4079
4091
4093
4099
4111
4127
4129
4133
4139
4153
PRIME
4157
4159
4177
4201
4211
4217
4219
4229
4231
4241
4243
PRIME
4253
4259
4261
4271
4273
4283
4289
4297
4327
4337
4339
PRIME
4349
4357
4363
4373
4391
4397
4409
4421
4423
4441
4447
PRIME
4451
4457
4463
4481
4483
4493
4507
4513
4517
4519
4523
PRIME
4547
4549
4561
4567
4583
4591
4597
4603
4621
4637
4639
PRIME
4643
4649
4651
4657
4663
4673
4679
4691
4703
4721
4723
PRIME
4729
4733
4751
4759
4783
4787
4789
4793
4799
4801
4813
PRIME
4817
4831
4861
4871
4877
4889
4903
4909
4919
4931
4933
PRIME
4937
4943
4951
4957
4967
4969
4973
4987
4993
4999
5003
PRIME
5009
5011
5021
5023
5039
5051
5059
5077
5081
5087
5099
PRIME
5101
5107
5113
5119
5147
5153
5167
5171
5179
5189
5197
PRIME
5209
5227
5231
5233
5237
5261
5273
5279
5281
5297
5303
PRIME
5309
5323
5333
5347
5351
5381
5387
5393
5399
5407
5413
PRIME
5417
5419
5431
5437
5441
5443
5449
5471
5477
5479
5483
PRIME
5501
5503
5507
5519
5521
5527
5531
5557
5563
5569
5573
PRIME
5581
5591
5623
5639
5641
5647
5651
5653
5657
5659
5669
PRIME
5683
5689
5693
5701
5711
5717
5737
5741
5743
5749
5779
PRIME
5783
5791
5801
5807
5813
5821
5827
5839
5843
5849
5851
PRIME
5857
5861
5867
5869
5879
5881
5897
5903
5923
5927
5939
PRIME
5953
5981
5987
6007
6011
6029
6037
6043
6047
6053
6067
PRIME
6073
6079
6089
6091
6101
6113
6121
6131
6133
6143
6151
PRIME
6163
6173
6197
6199
6203
6211
6217
6221
6229
6247
6257
PRIME
6263
6269
6271
6277
6287
6299
6301
6311
6317
6323
6329
PRIME
6337
6343
6353
6359
6361
6367
6373
6379
6389
6397
6421
PRIME
6427
6449
6451
6469
6473
6481
6491
6521
6529
6547
6551
PRIME
6553
6563
6569
6571
6577
6581
6599
6607
6619
6637
6653
PRIME
6659
6661
6673
6679
6689
6691
6701
6703
6709
6719
6733
PRIME
6737
6761
6763
6779
6781
6791
6793
6803
6823
6827
6829
PRIME
6833
6841
6857
6863
6869
6871
6883
6899
6907
6911
6917
PRIME
6947
6949
6959
6961
6967
6971
6977
6983
6991
6997
7001
PRIME
7013
7019
7027
7039
7043
7057
7069
7079
7103
7109
7121
PRIME
7127
7129
7151
7159
7177
7187
7193
7207
7211
7213
7219
PRIME
7229
7237
7243
7247
7253
7283
7297
7307
7309
7321
7331
PRIME
7333
7349
7351
7369
7393
7411
7417
7433
7451
7457
7459
PRIME
7477
7481
7487
7489
7499
7507
7517
7523
7529
7537
7541
PRIME
7547
7549
7559
7561
7573
7577
7583
7589
7591
7603
7607
PRIME
7621
7639
7643
7649
7669
7673
7681
7687
7691
7699
7703
PRIME
7717
7723
7727
7741
7753
7757
7759
7789
7793
7817
7823
PRIME
7829
7841
7853
7867
7873
7877
7879
7883
7901
7907
1000 rows selected.
Elapsed: 00:00:05.07
SQL>
SY. -
Is this the best way to test a prime number?
Ok so I think I finally got my program to work. I tested It with very big 8 digit prime numbers if that means anything. here are 2 Questions about my program"
-Is this a way of finding prime numbers? (does the program fulfill its purpose?)
and Second is there a smarter way of doing it?
Here is the program:
//This program tests if a number is a prime number
import java.util.Scanner;
public class Main
public static void main ( String args [ ] )
Scanner input = new Scanner( System.in );
int number;
int bob;
System.out.print(" Enter the number you wish to test:\n");
number = input.nextInt();
if (number == 1)
System.out.print(" 1 is divisible only by 1, therefore it is not prime or composite\n");
if (number == 2)
System.out.print(" It's Prime\n ");
for ( int test = 2 ; test < number ; test++ )
bob = number % test;
if ( bob == 0)
System.out.print("It's Composite\n");
return;
System.out.println("It's Prime");
}I got interested in this ...
//1. PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
//2. PrimeTester_SieveOfEratosthenes: found 3001134 primes <= 50000000 in 4422 milliseconds
//3. PrimeTester_SieveOfAtkin: found 3001134 primes <= 50000000 in 24843 milliseconds
... so Wkipedia's SieveOfAtkin algorithm apparently requires some serious optimization before it outruns the Greeks... see http://cr.yp.to/primegen.html for an optimized C implementation (which I can't follow).
PrimeTester_BruteForce.java//find all prime numbers upto the given maximum.
//Using the brute force method
//http://www.newton.dep.anl.gov/newton/askasci/1995/math/MATH039.HTM
//PrimeTester_BruteForce: found 3001134 primes <= 50000000 in 410500 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_BruteForce {
public static void main(String[] argv) throws IOException {
long start = System.currentTimeMillis();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_BruteForce.txt")));
int limit = 50000000;
int count = 0;
nextn: for (int n=2; n<=limit; n++) {
int top = (int)Math.sqrt(n);
for(int i=2; i<=top; i++) {
if(n%i==0) {
continue nextn;
out.print(n);
out.print(" ");
if(++count%20==0) out.println();
long took = System.currentTimeMillis()-start;
out.println();
out.println("PrimeTester_BruteForce: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
out.close();
PrimeTester_SieveOfEratosthenes.java/******************************************************************************
//find all prime numbers upto the given maximum.
//http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
limit = 1000000; // arbitrary search limit
// pressume all are prime
for (i=2; i<=limit; i++) is_prime[i] = true;
// eliminate multiples of each prime, starting with its square
for (n=2; n<=sqrt(limit); n++) {
if (is_prime[n]) {
for (i=n^2; i<=limit; i+=n) is_prime[i] = false;
// print the results
for (n=2; n=<limit; n++) {
if (is_prime[n]) print(n);
//PrimeTester_SieveOfEratosthenes: found 164185 primes <= 1000000 in 125 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_SieveOfEratosthenes {
public static void main(String[] argv) throws IOException {
long start = System.currentTimeMillis();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfEratosthenes.txt")));
int limit = 50000000;
int n, i;
boolean[] is_prime = new boolean[limit+1];
// pressume all are prime
is_prime[2] = true;
for (i=2; i<=limit; i++) {
is_prime[i] = true;
// eliminate multiples of each prime, starting with its square
for (n=1; n<=Math.sqrt(limit); n++) {
if (is_prime[n]) {
for (i=n*2; i<=limit; i+=n) {
is_prime[i] = false;
// print the results
int count = 0;
for (n=2; n<=limit; n++) {
if (is_prime[n]) {
out.print(n);
out.print(" ");
if(++count%20==0) out.println();
long took = System.currentTimeMillis()-start;
out.println();
out.println("PrimeTester_SieveOfEratosthenes: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
out.close();
PrimeTester_SieveOfAtkin.java/******************************************************************************
//find all prime numbers upto the given maximum.
//http://en.wikipedia.org/wiki/Sieve_of_Atkin
limit = 1000000; // Arbitrary search limit
array is_prime[5:limit] initial false; // Sieve array.
biginteger x,y,n,k; // Must be able to hold 5*limit: 4x^2 + y^2!
// put in candidate primes: integers which have an odd number of representations
// by certain quadratic forms.
for x:=1:sqrt(limit) do
for y:=1:sqrt(limit) do
n:=4x^2 + y^2; if n<=limit and n%12 = 1 or 5 then is_prime[n]:=not is_prime[n];
n:=3x^2 + y^2; if n<=limit and n%12 = 7 then is_prime[n]:=not is_prime[n];
n:=3x^2 - y^2; if n<=limit and x>y and n%12 = 11 then is_prime[n]:=not is_prime[n];
next y;
next x;
// eliminate composites by sieving
// if n is prime, omit all multiples of its square; this is sufficient because
// composites which managed to get on the list cannot be square-free
for n:=5:sqrt(limit) do
if is_prime[n] then for k:=n^2:limit:n^2 do is_prime[k]:=false; next k;
next n;
// Present the results.
print 2, 3; for n:= 5:limit do if is_prime[n] then print n; next n;
//PrimeTester_SieveOfAtkin: found 441 primes <= 1000000 in 203 milliseconds
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class PrimeTester_SieveOfAtkin {
public static void main(String[] argv) throws IOException {
long start = System.currentTimeMillis();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("PrimeTester_SieveOfAtkin.txt")));
int limit = 50000000;
int sqrt = (int)Math.sqrt(limit);
boolean[] is_prime = new boolean[limit+1]; // Sieve array.
int x, y, n, k; // Must be able to hold 5*limit: 4x^2 + y^2!
// put in candidate primes: integers which have an odd number of representations by certain quadratic forms.
for (x=1; x<=sqrt; x++) {
for (y=1; y<=sqrt; y++) {
//n=(4*(x^2)) + y^2; if (n<=limit && n%12 in(1,5)) is_prime[n] = !is_prime[n];
int xSq = (int)Math.pow(x,2);
int ySq = (int)Math.pow(y,2);
n = 4*xSq + ySq;
if (n<=limit && (n%12==1||n%12==5)) {
is_prime[n]= !is_prime[n];
//debug("A: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
//n=((3*(x^2)) + y^2; if (n<=limit && n%12==7) is_prime[n] = !is_prime[n];
n = 3*xSq + ySq;
if (n<=limit && n%12==7) {
is_prime[n]= !is_prime[n];
//debug("B: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
//debug(" if (n<=limit:"+limit+" && n%12:"+(n%12)+"==7");
//debug(" (3*(x^2)):"+xSq+" + (y^2):"+ySq);
//n=((3*(x^2)) - y^2; if (n<=limit && x>y && n%12==11) is_prime[n]= !is_prime[n];
n = 3*xSq - ySq;
if (n<=limit && x>y && (n%12==11)) {
is_prime[n]= !is_prime[n];
//debug("C: x="+x+", y="+y+", is_prime["+n+"]="+is_prime[n]);
}//next y
}//next x
// eliminate composites by sieving
// if n is prime, omit all multiples of its square; this is sufficient because
// composites which managed to get on the list cannot be square-free
// for (n:=5:sqrt(limit)) {
// if (is_prime[n]) for (k:=n^2:limit:n^2) is_prime[k]:=false;
for (n=5; n<=sqrt; n++) {
if (is_prime[n]) {
int nSq = (int)Math.pow(n,2);
for(k=nSq; k<=limit; k+=nSq) {
is_prime[k]=false;
//debug("D: n="+n+" is_prime["+k+"]="+is_prime[k]);
// Present the results.
int count = 2;
out.print("2 3 ");
for(n=5; n<=limit; n++) {
if(is_prime[n]) {
out.format("%d ", n);
if(++count%20==0) out.println();
long took = System.currentTimeMillis()-start;
out.println();
out.println("PrimeTester_SieveOfAtkin: found "+count+" primes <= "+limit+" in "+took+" milliseconds");
out.close();
//private static void debug(String msg) {
// System.out.println(msg);
} -
Plot xy graph using random number generator
How do i plot xy graph dynamically every 5 seconds with a random number generator?
X axis : Time
Y Axis : Random number generatorI've done tis so far. im able to plot dynamically every 1 second.
but the problem i am facing is The X axis display every 1 second.
i want it to be fixed 24 hours time format, and the data will gradually plots the data on y axis against x axis every one second, without changing the scale of the x axis (24hour time format) -
Arbitrary Number Generated before Sales Order Document number is Generated
I want to know which is the arbitrary number generated before the sales Order Document number is created. In which table the arbitrary number is stored?
The Exit which triggers the arbitrary number in the transaction VA01?Hi
You get the Arbitrary number throug the FM NUMBER_GET_NEXT.
interne Nummernvergabe
data: da_rc like inri-returncode.
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = da_numki
object = 'RV_BELEG'
importing
returncode = da_rc
number = vbak-vbeln.
And regarding userexit, there is
perform userexit_number_range using da_numki statement in include MV45AF0B_BELEG_SICHERN.
Regards
Raj -
Is any request number generates when i create a sap script??
hi Gurus
I want to know Is any request number generates when i create a sap script??
if it is generates then how to find that request number???Hello,
A simple solution to find out the request number if thisis not released is, logon to SAP system with diffrent user ID other then the request owner's ID, a pop up message appears informing whether to create a new task under the xisting TR number.
If the TR i already released, then go to table E071 table and pass the object name. you can find all the related Tr's for the object. -
Hello,
I'm a high school student and am making a program which calculates the next prime number greater than the inputed number. The rules are that you cannot use any other classes other than those that are imported, but I think you can use any class in lang (you can definitely use the math class).
The program determines how fast it took to find the prime number. Entering the number 9*10^16 (9 with sixteen 0s), my PC calculated it in about 22534 milliseconds (22 seconds). I'm trying to improve this since I've seen people do at about 7 seconds. Any ideas on how to make this program faster, about 15 seconds faster?
Here is my code for the best i could come up with:
import javax.swing.JOptionPane;
import javax.swing.JApplet;
import javax.swing.JTextArea;
import java.awt.Container;
public class PrimeFinder extends JApplet
public void init()
String ms = JOptionPane.showInputDialog("Please enter a number:");
long b = Long.parseLong(ms);
long base = b;
long num = 3;
long start = System.currentTimeMillis();
while(num<=Math.sqrt(base))
if(base%2==0 || base%num==0)
base++;
num=3;
else num+=2;
long time = System.currentTimeMillis() - start;
String result = "Prime Finder:\n\nBase Number:\t" + b + "\nNext Prime:\t" + base + "\nTime:\t" + time;
JTextArea y = new JTextArea();
y.setText(result);
Container container = getContentPane();
container.add(y);
}PS: please run my code on your PC to check how fast your PC does it before writing new code since a better PC will obviously do it faster with the same code.This is what I am using:
public static void main(String[] args)
String ms = JOptionPane.showInputDialog("Please enter a number:");
long b = Long.parseLong(ms);
long base = b;
double sqrt = Math.sqrt(base);
System.out.println("Best Before: 19469");
long start = System.currentTimeMillis();
for(long num = 3; num <= sqrt; num += 2)
if(base%num==0)
base++;
num = 3;
sqrt = Math.sqrt(base);
else
num += 2;
long time = System.currentTimeMillis() - start;
String result = "Prime Finder:\n\nBase Number:\t" + b + "\nNext Prime:\t" + base + "\nTime:\t" + time;
System.out.println(result);
}I see a very significant time change between the while loop and for loop. -
[Novice Help]what's wrong of my prime number programme !!~?
import javax.swing.*;
public class prime1 {
public static void main (String args[])
String number;
int n;
number = JOptionPane.showInputDialog( "Enter" );
n = Integer.parseInt( number );
for ( int counter = 2 ; counter < n ; counter++ ){
if ( n % counter != 0 )
System.out.println(
" It is a prime number ");
else
System.out.println(
" It is not a prime number ");
System.exit(0);
Why n only mod 2,but not mod all number which is smaller then n?
when i input 9 ,it is wrong ~
i discover that when 9 is mod 2 ,it will not continue to mod 3,4,5,6,7,8The else only applied to the lien directly after it as there were no brackets to collect the two statements in an else block.
This means that the program was going into the for loop, checking you if/else then always running System.exit(0) which stopped the program before the loop had finnished.
Your statement "it is prime" is also in the wrong place. This really should say "it is no divisible by " + counter
as there are still numbers to check.
Try this revised version and see if you can understand the difference:
import javax.swing.*;
public class prime1 {
public static void main (String args[]) {
String number;
int n;
number = JOptionPane.showInputDialog( "Enter" );
n = Integer.parseInt( number );
for ( int counter = 2 ; counter < n ; counter++ ){
if ( n % counter != 0 )
System.out.println("It is not divisible by " + counter);
else{
System.out.println("It is not a prime number");
System.exit(0);
System.out.println("It is prime"); -
How to calculate the 100.000st prime number as fast as possible
Hello,
We were doing some experiments trying to calculate the 100.000st prime number in labview as fast as possible.
Some of us got to about 7 seconds. Does anyone know a way to calculate it faster using labview?
KevHi Pluv,
the VI is mainly based on those Coding challenge linked by Raven's Fan...
And as this sounds like homework (or similar) I would suggest to read that old thread, read articles on Wikipedia, and then do some own coding instead of adorning with borrowed plumes... To calc primes is described in numerous places in the internet, all you need is reading and coding!
And here's you can look at my VI:
One correction to my first post: you only need to calc upto 1.3e6... The 100.000th prime is 1299709.
Message Edited by GerdW on 05-15-2010 01:36 PM
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Hi does java have a random number generator. If it does can you point me to it please. Thank you.
you can use "java.Math.random()" this function returns a value which is greater than or equal
to 0.0 and less than 1.It returns a double value,so you can multiply by 10 and cast it to int,so that it
can produce numbers between 0 & 9.Yes, you can do that. But, as stated before, java.util.Random has methods that are easier to use for random int values than using java.Math.random is for random int values. It all depends what the OP wants. The OP hasn't come back with additional questions, or to say that he found his answer. So, we don't know whether he has his answer (he has several options now!) or not. :) -
Random Letter & Number Generator
Hello:
I'm new to programming (FormCalc & JavaScript) and I'm using Adobe LiveCycle Designer ES 8.2 to create a dynamic form to post online. I need help with creating a "random letter & number generator" in code. The purpose is when someone opens the form online; I will create a unique number/letter combo on the form.
Any help or direction would be much appreciated. Thanks!Hi,
I believe you are in the wrong forum. This is a forum for Adobe
LiveCycle Collaboration Service (LCCS) , a real-time social
collaboration platform.
You need to visit other forums under LiveCycle
http://forums.adobe.com/community/livecycle/livecycle_es?view=discussions
Primarily you can look for LiveCycle Forms sub forum.
Hope this helps
Thanks
Hironmay Basu
Maybe you are looking for
-
My iphone power button is not working so today I decided to replace it, on opening few screws I was unable to continue as I was not able to open all the screws on the iphone. So far I had managed to disconnect display panel & battery only. So I decid
-
I recently bought a 60 gb ipod photo. however, when i try to upload songs onto it, it has an error message that says "the disk could not be read from or written to." this is an inconsistent message and occasionally one or two songs will work. i have
-
Hi Everyone, I'm new to Flash and am also experimenting with a Flash Media Streaming Server. I am trying to get video streaming to work with my new website, and the video so far plays great with no problems in web browsers such as Firefox/Safari, etc
-
I need Help
-
I need to update my system on my iPad how can I do that?