C++ :: Program To Generate Pairs Of RSA Keys Using Small Prime Numbers
May 21, 2012
I have been writing a program to generate pairs of RSA keys using small prime numbers. I have been using mpz_invert() to get a value for d for the private key. On small prime numbers it calculates the correct value, but on larger primes it calculates incorrect values.
I'm assuming there must be an upper limit to the values the mpz_invert() function can handle? If so, what is this limit to avoid erroneous values?
View 1 Replies
ADVERTISEMENT
Oct 22, 2014
Given a number "n" supplied by the user, write all the prime numbers less than or equal to "n"
not at all how to make the number I enter me for the numbers that I need even a couple makes the prime number if the command is used repeat for but and decision making but the truth is that I can think of no way to do for this exercise is that the prime numbers are those numbers which are divided only by 1 and themselves also
until the moment I have this code
#include <stdio.h>
#include <stdlib.h>
main(){
int n;
n=0;
printf("enter the desired number: ");
scanf("%f",&n);
system("pause");
}
View 5 Replies
View Related
Aug 30, 2014
I was investigating for the first time how to generate prime numbers with a considerably high upper limit, around 10^6 or so. I read about sieve's algorithm and tried to implement it using c#, as I had previously brute forced the generation. In Sieve's algorithm, instead of marking the values that were not prime I simply eliminated them, but I don't think that would make any difference. The issue is that my implementation of sieve's algorithm must be wrong, as when I establish the limit as 10^5 I get the following output:
Brute force:
Computation time: 00:00:00.0643539
Sieve's algorithm:
Computation time: 00:00:20:6934223
I have already checked that their generation of primes is correct, but I do not know why one is significantly slower than the other. Here is my code.
using System;
using System.Collections.Generic;
using System.Linq;
[Code].....
View 5 Replies
View Related
Dec 2, 2014
I have a program that gets prime numbers that doesn't work. It looks like it works for all prime numbers except odd non-prime ones. Here is the code:
Code:
#include <iostream>
using namespace std;
bool isPrime(int prime) {
while(true) {
int track = 0;
[Code] ...
View 3 Replies
View Related
Apr 28, 2013
I wrote a program which sends a starting and ending range to other processes and the processes calculate the prime numbers in that range and return the count of prime numbers to the head process, process 0. But this is not working properly at the moment. I realize I still have to split up the range based on how many processes I have...I still have not figured out how I want to set that up. I
Code:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int isPrime(int num);
int main(int argc, char **argv){
}
[code]....
View 7 Replies
View Related
Oct 4, 2014
This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.
#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()
[Code] ....
View 3 Replies
View Related
Jan 29, 2013
Here is what I have:
#include <iostream>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;
[Code] .....
This is the output after compiling when I enter 10 as 'x':
3
5
5
5
7
7
7
7
7
9
View 1 Replies
View Related
Nov 4, 2014
I am a C++ beginner with no programming background. I need to write a lottery program that generate 5 non-duplicate numbers between 1 and 20. Here is my code and it just wont work.
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));
int lottery[5] = { 0, 0, 0, 0, 0 }, count = 0, rand_lottery;
[Code] ....
View 2 Replies
View Related
Dec 15, 2014
I need numbers next to each other to be sorted (in increasing order).On the CPU I'd do something like this:
for(int i=0; i < length; i+=2) {
if(a[i]>a[i+1]) {
switch places...
}
}
But how would I do this using parallel_for_each (C++AMP) ? I need this for some algorithm that works with very long arrays and I think GPU would do this faster than CPU (even if I use all threads).
View 3 Replies
View Related
May 29, 2013
I'm trying to write a program that prints all of the prime numbers to the screen. I'm getting angry because it only prints EVERY number. I think it has something to do with the bool change not being able to leave the for-loop but how to fix it.
Code:
#import <stdio.h>
#include <stdbool.h>
int main(void){
printf("
The Primes Are: 1");
[Code] ....
View 3 Replies
View Related
Dec 10, 2013
Alexandra has some distinct integer numbers a1,a2...an.
Count number of pairs (i,j) such that:
1≤ i ≤ n
1≤ j ≤ n
ai < aj
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer n denoting the number of numbers Alexandra has. The second line contains n space-separated distinct integers a1, a2, ..., an denoting these numbers.
Output
For each test case, output a single line containing number of pairs for corresponding test case.
Constraints
1 ≤ T ≤ 4
1 ≤ n ≤ 100000
0 ≤ ai ≤ 109
All the ai are distinct
Example
2
2
2 1
3
3 1 2
Output:
1
3
Explanation
Case 1: Only one such pair: (2,1)
Case 2: 3 possible pairs: (2,1), (2,3), (3,1)
as I understand the problem is just counting how many Ai's are 1 <= Ai <= N and then apply ((R*(R-1))/2), R is the count of valid Ai's
My actual code is
#include <stdio.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define getNumber getchar()
#define getString getchar()
[Code] ....
View 4 Replies
View Related
Nov 11, 2013
how to make a programm in native c++ which print out all prime numbers less than or equal to given number????????
View 5 Replies
View Related
Feb 9, 2013
I want to store a very small number - too small for even a long double. However, I don't need the number to be stored very precisely - in fact, all I really need is the order of magnitude of the number. For example, the number 5.205849034425 X 10^-381 can just be stored as an integer of -381 for my purposes. I don't really care about the precision of the 5.205849034425 part.
The reason I get this very small number, is because I am multiplying together thousands of numbers, all of which are around 0.0001 in value. So, one way to do this would be to store all these individual values as simply their order of magnitude (e.g. -4) and then instead of multiplying the numbers, I would just add up their orders of magnitude. However, I am wondering whether there is a way in C++ to do this without me having to change the way I store my data - I still would like to keep the original values if possible.
View 2 Replies
View Related
Aug 24, 2014
I'm a new coder for C++, and I've recently learned java before starting this programming language. I'm attempting to find all prime numbers up to the number a user enters (i.e. User enters 10, System shows "1,2,3,5,7"),
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char** argv) {
int num;
cout << "Enter a positive number." << endl;
[Code] ....
I've been looking at my forloop, and I can't seem to pinpoint the problem with it.
View 1 Replies
View Related
Apr 10, 2013
Whenever I try to call merge sort on large numbers say n=10000000. It gives an error. It works fine for small numbers, even though I have declared my Lists on the heap.
The below code is just the divde part.
List<long>* Merge(List<long> *ParentList) {
if((ParentList)->Length==1) {
return ParentList;
[Code] .....
View 1 Replies
View Related
Apr 4, 2015
Im trying to do a small program that will create multiples of the previous line *2, and spit out the anwser in seperate lines (as many times as the user wants)
Example if i wrote it in a bad way
2
4
8
16
32
etc.
At this time my code looks likes this, now im planing to get my hands on the IF statment
using System;
using System.Collections.Generic;
using System.Linq;
[Code].....
View 6 Replies
View Related
Apr 18, 2014
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");
[Code] .....
View 1 Replies
View Related
Sep 21, 2014
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
1 3 4 5 6 8 10 13 14 16 17 18 19 20 25
3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________
Count = 8, in this case..
I think it's not very difficult to do, but i just can't see how to do it.
#include <iostream>
#include <vector>
#include <numeric>
[Code]....
View 3 Replies
View Related
Feb 21, 2014
Code:
#include<stdio.h>
int main(){
int num,i,count,min,max,sum=0;
printf("Enter min range: ");
scanf("%d",&min);
[code]....
when I ran the program , I got "4" with prime numbers. I only way I was able to remove the "4" was this "num!=4".
View 1 Replies
View Related
May 27, 2013
I was going through a book I have about C trying to learn about arrays, and one of the first few examples of what could been done with an array was showing how to use an array to generate a list of prime numbers. I've been staring at this program for about an hour trying to understand how it works (it does), but the workings of one for loop within the program.
Code:
#include <stdio.h>
#include <stdbool.h>
int main () {
int p, i, primes[50], primeIndex = 2;
bool isPrime;
[Code]...
So that is saying in order for this loop to go on, really two conditions must be met since there's that && operator. isPrime must be true (I think that's what it means by just having "isPrime" and not setting it equal to anything) and p / primes[i] must be greater than or equal to primes[i].So at the beginning of the loop, since i = 1, p = 5 (as per surrounding loop), and prime[i] = 3 ( as per the variable assignment at the beginning of the program ), the loop condition would be "isPrime && 5 / 3 >= 3"
"5 / 3 >= 3" The loop should stop right there! 1.666666667 is NOT greater than or equal to 3!
View 14 Replies
View Related
Feb 3, 2014
Code:
#include <stdio.h>
int find_next_prime(int num);
int is_prime(int num);
int main()
[Code]......
How would I go about counting the number of times a factorial has a specific prime number?
For example, 5! = (2^3)*(3^1)*(5^1), 6! = (2^4)*(3^2)*(5^1).
How would I begin to design my find_prime_count function in order to count how many times each occurs? My program is to read in a number between (2<=N<=100) from a text file and output the results exactly like above which I still have to figure out after, I'll assume I have to use fscanf.
View 8 Replies
View Related
Feb 17, 2013
I have an assignment where I have to use two for loops. I need to ask the user for any two numbers and be able to list all the numbers in between and their factors and state whether or not the number is prime or not.
View 2 Replies
View Related
Mar 3, 2014
Write a c++ program to print out the first n prime numbers and the sum of the first n prime numbers.
View 7 Replies
View Related
Mar 9, 2015
I keep getting this error:
||In function 'int main()':|
|19|error: too few arguments to function 'int isPrime(int, int)'|
|13|note: declared here|
Code:
#include <iostream>
#include <fstream>
using namespace std;
int isPrime(int , int);
int main() {
int result = 0;
[Code] ....
View 2 Replies
View Related
Sep 25, 2014
The object is to have the user enter in the number of days then the day the calendar would start on. This part I was able to achieve and run okay. Once I wanted to get the values/days that were prime to have a P besides them this is where I ran into trouble. In this case P stands for prime numbers.
The issue I have is that some of the values that are prime have the correct P but others have the P as well such as 9, 15, and 25 - which are not prime numbers.
I was able to create a program that checked for prime numbers separately but I had issues merging them. Below is the merged code followed by the prime checker.
#include <stdio.h>
int main(int argc, const char * argv[]) {
int i, N, Start;
int j, GetNumber, PrimeNumber = 0;
[code].....
View 2 Replies
View Related
Mar 17, 2013
I'm trying to generate random numbers so that I can assign people to teams. So far I have come up with this
Code:
int generateTeam(){
int i, teamNumber, c, n;
for (c = 0; c <= 5; c++) {
n = rand()%100 + 1;
}
[code]....
}//end generateTeam I'm not sure how to make it so that I can exclude the previous random number when generating the next one. As an example, I have 22 students and I get the number 19. Now I can't have 19 again because that guy already has it.
View 3 Replies
View Related