[PYTHON] Multiple judgment program (not completed)

at first

If you are using Qiita, it may be too easy problem, but please think that it is a problem of competitive programming and solve the following problem

An integer is entered.
If odd"HAPPY",If even"LUCKY"Create a program that outputs

It's easy. Appropriately

N=int(input())
if N%2==1:
Abbreviation

That's enough. However, I was foolish and made such an input.

(input screen)
>>> n(n-1)

No, the input is an integer! Of course there is a rush, but if n is a natural number, this formula will be an even number and I would like to display it as "LUCKY".

So the purpose of this time is "Let's make a multiple judgment program for character expressions!"

Program flow

Although it is a basic flow, we aim to create a program that automatically performs mathematical induction. As an expression to explain briefly Use n (n + 1) (2n + 1). If 1/6 is added to this, it's the formula of the sum of squares that everyone loves. That is, n (n + 1) (2n + 1) is a multiple of 6.

flow

(Input of what multiple to judge)
>>>6
(Input of judgment formula)
>>> n(n+1)(2n+1)
___________________________________
(Contents of the program)
(Deploy first) 2*(n*n*n)+3*(n*n)+n
(Then n=Set to 1) 2+3+1
(Determine if this is a multiple of the first number entered) ok
(The next expanded equation is assumed to be a multiple of 6) 2*(n*n*n)+3*(n*n)+n is a multiple of 6
(n to n+Substitute 1) (2*(n+1)*(n+1)*(n+1))+(3*(n+1)*(n+1))+(n+1)
=2*((n*n*n)+(3*n*n)+(3*n)+1)+3*((n*n)+(2*n)+1)+(n+1)
=2*(n*n*n)+9*(n*n)+13*n+6
(Divide each coefficient by 6 and leave a remainder) 2*(n*n*n)+3*(n*n)+n
(Subtract with the assumption that it is a multiple of 6) 0
When it reaches 0, the program ends

(If it does not reach 0, subtract more from the remaining formula)
(This is repeated until just before the highest-order coefficient becomes negative.)
(If it does not reach 0 even after doing so, perform induction again with the remaining formula.)
(If this is repeated, the highest-order coefficient gradually decreases and eventually becomes 0.)
(The order has dropped by one)
(If the coefficient of the next degree is negative-I'll multiply by 1(It may be solved if the remainder is taken as a positive integer))
(You can repeat the same thing)
(Since the degree is finite, if you repeat this for any expression, only the integer term will remain someday.)
(Success if the remaining number is a multiple of 6)

It will be the flow. It is almost the same principle as Euclidean algorithm. I just extended it to a polynomial.

It's the 3rd day trying to implement it.

The bug doesn't stop Please help me (I'll post it for correction when it's complete)

Recommended Posts

Multiple judgment program (not completed)
Senryu Judgment Program