Prove that p^3 - 1 is a composite number given P > 2 [closed] - proof

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
In order to prove a number composite I have to prove that p^3 - 1 = ab
With a and b not being 1 and itself. Its given that p > 2.
I factor it out with differences of squares
p^3 - 1 => (p - 1)(p^2 + p + 1)
And I don't really know what to do next. How do I involve p > 2 into the proof.

Its a composite number only if its a product of two numbers a and b both of which are greater than 1. If p = 2, then a would be 1.
If (p > 2) - then
(p - 1) > 1 and
(p^2 + p + 1) > 1.

Just use induction.
Base case p=3, p**3-1 = 8.
Inductive case: use your factorization.

Related

MYSQL order by (whole)number and text [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 2 years ago.
Improve this question
I'm trying to order a list with a query :
select * from processus order by numero_processus + 0 asc;
The problem is I got letters in some. I want the numbers first and then the letters
0
J
B
C
D
E
F
G
H
I
J
K
A
FCR 1
FCR 2
PB
M
N
L
L
1.1
1.2
How can I do ? Thank you.
If you want the numbers first, you can use conditional logic. If by "number" you mean a string that begins with a number:
order by ( (numero_processus + 0) = 0 and (numero_processus <> '0') ) desc,
numero_processus + 0
If you want "full" numbers only (rather than just leading digits), then you can use regular expressions. This should be close enough:
order by ( numero_processus regexp '^[-]?[0-9]+[.]?[0-9]*$' ) desc,
numero_processus + 0

Query for students passed or not passed in specific Subjects [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 3 years ago.
Improve this question
I have a Table with Column Headings:
ID Student_Name
Roll_Number
Subject1MarksObtained
Subject1TotalMarks
Subject2MarksObtained
Subject2TotalMarks
Subject3MarksObtained
Subject3TotalMarks
Subject4MarksObtained
Subject4TotalMarks
I want to write a query to output the results for individual student who have pass at least three of the subjects.
Without seeing the data, lets make some assumptions:
A pass is awarded for a subject if the marks obtained for that subject are equal to or more than 50% of the total marks available for that subject.
The name of the table is called Enrollment
To return a list of students who have passed at least 3 subjects we can use a query similar to the following:
This solution uses CASE to evaluate a 1 for a pass and a 0 for fail for each subject, then we sum those results and only return rows that have a score of 3 or more.
SELECT ID, Student_Name, Roll_Number
FROM Enrollment
WHERE
( CASE WHEN (Subject1MarksObtained / Subject1TotalMarks) >= 0.5 THEN 1 ELSE 0 END
+ CASE WHEN (Subject2MarksObtained / Subject2TotalMarks) >= 0.5 THEN 1 ELSE 0 END
+ CASE WHEN (Subject3MarksObtained / Subject3TotalMarks) >= 0.5 THEN 1 ELSE 0 END
+ CASE WHEN (Subject4MarksObtained / Subject4TotalMarks) >= 0.5 THEN 1 ELSE 0 END
) >= 3
There are different way to approach this, but this query is simple to read and gets the job done.
If you are querying an access table, then CASE WHEN is not supported but you can use IIF or SWITCH to achieve the same results:
SELECT ID, Student_Name, Roll_Number
FROM Enrollment
WHERE
( IIF( (Subject1MarksObtained / Subject1TotalMarks) >= 0.5, 1, 0)
+ IIF( (Subject2MarksObtained / Subject2TotalMarks) >= 0.5, 1, 0)
+ IIF( (Subject3MarksObtained / Subject3TotalMarks) >= 0.5, 1, 0)
+ IIF( (Subject4MarksObtained / Subject4TotalMarks) >= 0.5, 1, 0)
) >= 3
Let's instead start by fixing your broken schema. A normalised design might look somewhat as follows:
Student
ID
Student_Name
Roll_Number
Results
StudentID
Subject
Mark

how to use Comma Seperator in sql? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have 4 columns one has id and other columns (A,B,C) has binary values.
I want the results like, columns(A,B,C) which has value = 1.Then particular Column name must be displayed in new column(D) with comma separated values.
I want the results like below. Can anyone please help me?
Id A B C D
1 1 1 0 A,B
2 0 1 0 B
3 0 1 0 B
4 1 0 1 A,C
5 1 0 1 A,C
A simple CASE expression will do it:
SELECT *,
D =
STUFF((
CASE
WHEN A = 1 THEN ',A'
ELSE ''
END +
CASE
WHEN B = 1 THEN ',B'
ELSE ''
END +
CASE
WHEN C = 1 THEN ',C'
ELSE ''
END
), 1, 1, '')
FROM tbl

Using multiple OR in SQL [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 8 years ago.
Improve this question
I need to write a query which should check if there is at least one column which has a value greater than 0 (>0) in the table. Currently, I have written a 'WHERE' clause with multiple OR conditions. I suspect that this may not be the best way of doing this (may be use SUM?). Seeking opinion from SQL experts.
WHERE raw_0 >0 OR raw_1 >0 OR raw_2 >0 OR raw_3 >0 OR raw_4>0
You can use
WHERE (raw_0 >0 OR raw_1 >0 OR raw_2 >0 OR raw_3 >0 OR raw_4>0);
As per your question. As dnoeth commented, is the easiest to write and understand (and probably the best for the optimizer as there's no calculation involved)
Alternatively you can use:
WHERE ((RAW_0 + RAW_1 + RAW_2 + RAW_3) > 0);
The above condition would be satisfied IF and only IF, atleast one of the values is >0.
You can also use concat operator to concat the strings and check if the concatenated string has value other than zero:
WHERE TO_NUMBER ( RAW_0 || RAW_1 || RAW_2 || RAW_3 ) > 0
Test data for 3rd query:
select 'YES value' data from dual where TO_NUMBER ( 1 || 2) > 0 ;
select 'NO value' data from dual where TO_NUMBER ( 0 || 0) > 0 ;
If the values can only be non-negative, as in one of the OP comment then you can check the multiplication
WHERE raw_0 * raw_1 * raw_2 * raw_3 * raw_4 > 0
but that will check if every value as positive. To check if only one is positive we can negate this logic using the SIGN function
WHERE (1 - SIGN(raw_0))
* (1 - SIGN(raw_1))
* (1 - SIGN(raw_2))
* (1 - SIGN(raw_3))
* (1 - SIGN(raw_4)) = 0
(1 - SIGN(value)) return 1 when the value is zero and 0 when the value is positive, so if at least one value is positive the product will be 0.

MySQL add 0 when < *.10 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I can't seem to find/create a working query which will update the x column with an extra zero when value after the dot is below .10 - I've got column x with values;
7.3
5.3
0.14
I am trying to update the column so when the value after the dot is below .10 it adds a zero, above example will eventually need to look like;
7.03
5.03
0.14
Is there a way I can do this using an mysql UPDATE-query?
Many thanks.
First of all, 0.03 is not equal to 0.30, so i believe what you want is 7.30 and not 7.03. To do this, you need to alter your table column to display two decimal digits:
my_magic_column float(3,2)
where 3 is the total number of digits and 2 is the number of decimals to show.
I don't really get idea behind such operation but it's pretty simple.
SELECT CASE
WHEN INSTR(id, '.') = 0 THEN id
ELSE CASE
WHEN CAST(SUBSTRING_INDEX(id, '.', -1) AS UNSIGNED) < 10 THEN
CONCAT(SUBSTRING_INDEX(id, '.', 1), '.0', CAST(SUBSTRING_INDEX(id, '.', -1) AS UNSIGNED))
ELSE id
END
END as result
FROM table_name
UPDATE table_name SET id = CASE
WHEN INSTR(id, '.') = 0 THEN id
ELSE CASE
WHEN CAST(SUBSTRING_INDEX(id, '.', -1) AS UNSIGNED) < 10 THEN
CONCAT(SUBSTRING_INDEX(id, '.', 1), '.0', CAST(SUBSTRING_INDEX(id, '.', -1) AS UNSIGNED))
ELSE id
END
END
But before using this, think once again about your schema and what are you trying to do. I don't think you'll need this then.
Looks like what you want to do is:
update TABLE set YOUR_NUMBER = (FLOOR(NUMBER) + (NUMBER-FLOOR(NUMBER))/10)
where FLOOR(NUMBER*10) = NUMBER*10
FLOOR(NUMBER) - take the integer part and add to it:
(NUMBER-FLOOR(NUMBER))/10 - the fraction part of the number - divided by 10
The where condition checks that there's only one digit after the dot