# Informatics1-2019/HW7

(eltér) ←Régebbi változat | Aktuális változat (eltér) | Újabb változat→ (eltér)

# Sage

6 points

The exercises should be done via a sage function:

```def nameofthefunction(input):
...
...
return ...
```

## Relative primes

3 points

Write a function called relativeprimes with a positive integer as input. The output should be a univariate polynomial such that:

• its variable is x
• every coefficient is 1
• only the powers of x should be in the polynomial where exponent less than n and relative prime to n.

Example:

```>>> relativeprimes(9)
x^8 + x^7 + x^5 + x^4 + x^2 + x
```

Use list comprehension and sum

## Pythagorean primes

3 points

Find Pythagorean triplets where:

• every term is a positive integer
• they are in a descending order
• the sum of the squares of the last two is the square of the first one
• at least on of the three is a prime

Define a function called pythagorean with one input (n) and return all such triplets up to n.

Example:

```def pythagorean(n):
...
...

pythagorean(100)
```
```[(5, 4, 3),
(13, 12, 5),
(17, 15, 8),
(29, 21, 20),
(25, 24, 7),
(37, 35, 12),
(41, 40, 9),
(53, 45, 28),
(73, 55, 48),
(61, 60, 11),
(97, 72, 65),
(89, 80, 39),
(85, 84, 13)]
```

## Handing in

Send the code of the functions in the email!