How can I select the correct number? [closed] - primes

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am given a list of prime numbers in a sorted order. The size of the list can be minimum '5' or maximum '10'.
Example list:- '2,5,7,11,29' .
I also have a machine which I can use only for 1 time.
I have to select any prime number (say x) from the list and give it as the input to machine.
Machine will give the output of x^2 modulo P . (Only machine knows the value of 'P' and it is a fixed value)
Where , 'P' is the prime number I have to guess.
One more important property:- 'P' is always a prime number which belongs to the list.
How can I find the correct value which machine knows but I don't ?

In your particular example set, {2,5,7,11,29}, choosing either 5 or 7 to be x would provide a set of unique, telling results for x^2 mod P, where P is a prime in the example set. The set of results for 5 is {1, 0, 4, 3, 25}; and for 7, it's {1, 4, 0, 5, 20}.

Related

How to move negative elements of marix's back diagonal forward [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a rectangle-shaped matrix:
int arr[3][4] = {1,2,-3,4,
5,-6,7,8,
9,1,2,3};
And I need to move negative items forward along the back diagonal
1, 2, -, 4,
5, - ,7 ,8,
Diagonal:-, 1, 2, 3
like this:
int arr[3][4] = {1,2,9,4,
5,-3,7,8,
-6,1,2,3};
Is it possible to do this?
Yes, it's possible.
You have 3 rows and 4 columns.
Loop over the rows
Loop over the columns in the current row
Is the value in the current [row][column] less than 0? If so, swap the value with the value in [row+1][column-1].
Note: row+1 and column-1 may be out of bounds so you need to add logic for wrapping when reaching the boundaries of your array.

The most frequent range of numbers in an array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I know there are lot of topics about "The Most frequent Number in an array"
But I'm looking for code that can show me the most frequent range of numbers in an array. I couldn't find any topic about that tho.
Lets say there is an array with these values { 1 ,2 ,2 ,5 ,8 ,8 ,9 ,10} and the range is +-1...
most frequent range of numbers would be 8-10.
Is this possible? Can anyone help please?
Iterate through your values array, and for each value v, increase the count for the specific value v as well as for the values +/- 1, i.e. for v-1 and for v+1. Then, find the value with the highest count, let's call this value v_maxcount; the range is then v_maxcount -1 .. v_maxcount + 1.

Identification possibility of sorting an array by deleting not more than one element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Program gets a number of int arrays with size [2; 2000]. The question is: can that arrays get sorted after deleting not more than one element.
Examples:
2 16 3 3 - after deleting '16' it would be non-increasing array.
4 16 3 15 - there is no way to make it sorted.
Simple way: deliting first incorrect element and checking the fact of sorting. It takes too much time if there is a great number of arrays or that arrays are big-sizes.
Except cases, there incorrect element is first or last, and there array size is less than 4, in what way cheking that possibility can be accelerated
simply iterate through the array, and if you notice N_x > N_x+1 remove N_x, and mark that you removed 1 number...
in case you found another N_y > N_y+1 where y!=x, then it can't be sorted.
I'll leave the implementation for you, as it is your homework after-all.

Write a Regular Expression which identifies numbers divisible by 11 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For a study I am doing everyone gets assigned a unique number.
All unique numbers are divisble by 11 (this is done because it makes sequential numbers quite different from each other).
I would ideally like a regex which I can use to check that the number entered in the study_id field is an acceptable value - e.g divisible by 11.
I will have leading zeroes to a maximum of 5 digits
So:
00011 - Acceptable
00012 - Not Acceptable
13211 - Acceptable
13221 - Not Acceptable
Any suggestions gratefully received
This isn't possible because there are no textual similarities between numbers that are divisible by 11. Regex is used for text matching.
For example 000165 is divisible by 11 as is 00011.
The best way to validate the number is to divide it by 11 and see if there is any remainder. So in Excel you'd do this:
=IF(MOD(165, 11) = 0, "VALID", "INVALID")
Or C# you'd do something like this
bool isValid = 165 % 11 == 0;
(Disclaimer I'm not familiar with ODK so I can't provide a suitable sample; I've just guessed on the best language to write in)

C++ prime number logic [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a program that will output whether a number is prime or not. although, I'm trying to make it a little more complicated. I created a vector which I now want to store every prime number up to and including the number input by the user.
And then for the number input by the user (i.e. if the user types 13) will return true for the function hence it is a prime number. Here are some examples:
**U
primechecker() : plist(2) {;}
bool operator()(int);
3 5 7
then 3 5 6 7 7
The reason your vector is starting with two zeros is because you are initializing it with two elements of the default constructor:
primechecker() : plist(2)
Check out the documentation of std::vector (you are using the 'fill constructor')