## Is there a way to numerically solve on python a large number of uncoupled of 1st order differential equations?

I am looking for a way to numerically solve on python a large number of uncoupled of 1st order differential equations in a time-efficient manner. Is there a method you would recommend?

## elementary number theory – Find the hundredth place digit in 2008^2007^2006^…^2^1.

Find the hundredth place digit of 2008^2007^2006^……2^1.
Answer: Given M=2008^2007^……^2^1, let k1=2007^2006^…^2^1, k2=2006^2005^……^2^1 , k3= 2005^2004^……^2^1 .
Then M=2008^k1, k1=2007^k2, k2=2006^k3 . Now mod(M,1000)=mod(2008^k1,1000)=mod(8^k1,1000)…(1). Since 1000=8125,we find mod(8^k1,8) and mod(8^k1,125). Mod(8^k1,8)=0=>8^k1=8m1…(2), m1 being positive integer.
Since phi(125)=100,( phi= Euler’s phi function )mod(8^100,125)=1…(3).
Now mod(k1,100)=mod(2007^k2,100)=mod(7^k2,100)…(4).
Since phi(100)=40,mod(7^40,100)=1…(5). Now mod(k2,40)= mod(6^k3,40)=16,since k3>2. =>k2=40s+16=>mod(7^k2,100)=mod(7^16,100)=1…(6). From (4) mod(k1,100)=1=>k1=100t+1=>mod(8^k1,125)=mod(8,125) using (3).
So 8^k1=125m2+8=8m1,using (2). So8(m1-1)=125m2=>8 divides m2.
=> m2=8m3. So 8^k1=125
8m3+8=1000m3+8=>mod(8^k1,1000)=8.
From (1) it follows that hundredth place digit of M is 0.

## Solution discussion on the best way to reverse a number in Python

I’m practicing some python exercise and I have some doubts about the solution of reversing a number. Example, 42 -> 24, -314 -> -413.

The books has this solution:

def reverse(x: int) -> int:
result, x_remaining = 0, abs(x)
while x_remaining:
result = result * 10 + x_remaining % 10
x_remaining //= 10
return -result if x < 0 else result


My solution:

def reverse_digit(x: int) -> int:
s = str(abs(x))
result = s(::-1)
if x >= 0:
return int(result)
else:
return int("-" + result)


The book says that converting the number to string would be a brute-force solution but don’t they have the same time complexity, O(n)?

Is the book solution that much better than mine (that in my opinion is much simpler and easy to read)?

## I’m using Python, to find all the pythagorian triplets within the number 1000, but this takes around 20 minutes to execute on my computer

If there is anyway in which I can make this code run faster, please let me know.

This is the code

for a in range(1,1001):
for b in range(1, 1001):
for c in range(1, 1001):
if pow(a, 2) + pow(b, 2) == pow(c, 2):
print(str(a) + "," + str(b) + "," + str(c))


If there is anyway in which I can make this code run faster, please let me know.

Thank you.

## database design – Cardinality in a Logical Model by number of rows Vs natural relationship between entities

How should one determine Cardinality in a Logical Model ?

Should it be based on how the rows of an entity relate to another entity or should we consider the natural relationship between the entities i.e. conceptual relationship between the entities ?

Example: If I have an entity Course and an entity Course Type, what would be the cardinality ? Each course can have only one course type. For example, Bachelor of Arts is a course of course type Bachelors and Master of Science is of course type Masters

If I have Course Type as part of Course entity, then Course Type would only contain list of valid course types and it would be “many-to-one” (non-identifying) as there are many courses which will could 1 course type.

On the other hand if I model it in such a way that Course Type entity has Course ID (foreign Key) and Course Type , then the relationships between Course and Course Type is “one-to-one” (identifying).

Basically what I am trying to understand is, which one the following is right ?

each course has one course type OR many courses have one course type

How should one make this decision ? Are there any guidelines ?

P.S. : I am a beginner and using Oracle Data Modeler

## combinatorics – Finding number of permutations to form lists.

Want to know how to find number of arrangements for selecting a $$5$$ member list from $$12$$ teachers and $$14$$ students, such that least one student and one teacher must be included?

I find solving it difficult as that would include cases where second person in a category ( two categories: student, teacher) is selected before the first. So, for that reason the strategy of first finding combinations is not applicable, as cannot simply multiply by $$5!$$.

For illustration, have taken smaller example to form $$3$$-person list from $$4$$ teachers and $$4$$ students.

My solution is stated below. Request vetting. Also, is there any other approach to solve the original problem, apart from an extension of the below solution.

Let S1 be the first student selected, T1 be the first teacher selected. Similarly, for S2, T2.

Let, $$a_1 =$$#ways S1 can be selected,
$$b_1 =$$#ways T1 can be selected,
$$a_2 =$$#ways S2 can be selected,
$$b_2 =$$#ways T2 can be selected.
Note that if $$a_2$$ is greater than one, then $$b_2=1$$, and vice-versa.

The lists of size three can be formed by always having the first person in each category selected first. So, need arrangements with S1 before S2, & T1 before T2.

So, the possible ways are:

1. $$a_1a_2b_1times 2!$$, as there can be swap between S2, T1
2. $$a_1b_1b_2times 2!$$, as there can
be swap between S1, T1

Sum of above is :
$$(a_1a_2b_1 + a_1b_1b_2)times 2!= (4C1times3C1times4C1 + 4C1times4C1times3C1)times 2!$$
$$(4times3times4+4times4times3)times 2 =96times 2 = 192$$.

## python – Number of occurrences of strings in array

This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem).

We’re given an array of strings and an array of queries, and have to return an array of the number of occurrences of each query in the array of strings.
For example: s = (‘ab’, ‘abc’, ‘aba’, ‘ab’). q = (‘ab’, atr’, ‘abc). We need to return (2, 0, 1).

The constraints are 1 <= n <= 1000, 1 <= q <= 1000, where n and q are the number of strings and queries respectively, and 1 <= |strings(i)|, |queries(i)| <= 20.

Here is my code:

def matchingStrings(strings, queries):
results = ()
dic = {q:0 for q in queries}
for s in strings:
if s in dic: dic(s) += 1
for q in queries:
if q in dic: results.append(dic(q))
return results


Is there anything I can optimize? Speed, memory usage? Anything else?

## combinatorics – Number of partitions of an integer with a fixed number of parts

Is there an easy way in Mathematica to find the number of partitions of $$n$$ into $$k$$ parts? Or equivalently, the number of partitions of $$n$$ with largest part equal to $$k$$?

I realize the function IntegerPartitions[n,{k}] will return a list of all such partitions, which I could count, but I am wondering if there is a more efficient method.

## algorithms – Number of words with substrings from the dictionary

Thanks for contributing an answer to Computer Science Stack Exchange!