Procedures and functions


Plus
Pin


Problem description Progress
ID 34843. *Friendly numbers on the range
Темы: Procedures and functions   

Write a program that finds all pairs of friendly numbers in a given range. Use a function that calculates the sum of the divisors of a number and a function that determines whether two numbers are friendly or not. You should have TWO functions in your program

Input: The input string contains two natural numbers – range bounds and . It is guaranteed that ≤ .

Output: The program should print all pairs of amicable numbers in the given range on one line separated by a space. Each pair must be enclosed in parentheses, separated by spaces. There should not be extra spaces at the beginning and at the end of the line.

If there are no friendly numbers in the given range, the program should output 0.

Examples
# Input Output
1 1 100 0
2 200 500 (220,284)

ID 42839. Pixel screen
Темы: Procedures and functions    Tasks for procedures and functions   

The pixel screen displays each digit as a 3x5 picture.

1 2 3 4 5
 *
 *
 *
 *
 *
***
  *
***
*
***
***
  *
***
  *
***
* *
* *
***
  *
  *
***
*
***
  *
***
6 7 8 9 0
***
*
***
* *
***
***
  *
 *
*
*
***
* *
***
* *
***
***
* *
***
  *
***
***
* *
* *
* *
***

The input to the program is a natural number n (n <= 109).

Print this number as a picture on a pixel screen. Print each number on a new line. The order of the digits must match the order of the digits in the original number (that is, the first digit is displayed first, then the second, etc.). If there is nothing else in the string after the asterisk (*), then no spaces are required.

 
 
Examples
# Input Output
1 12
 *
 *
 *
 *
 *
***
  *
***
*
***

ID 42862. Right triangle
Темы: Procedures and functions   

Alice is studying symbolic graphics and wants to draw a right triangle made of stars with legs equal to 5. Write a triangle() function that will display the right triangle drawn in the example output.< br />  

Examples
# Input Output
1  
*
**
***
****
*****

ID 42865. Right Triangle - 2
Темы: Procedures and functions   

Alice is studying symbolic graphics and wants to draw a right triangle made of stars with legs equal to 5. Write a triangle() function that will display the right triangle drawn in the sample output.
 

Examples
# Input Output
1  
*****
****
***
**
*

ID 42867. Right Triangle - 3
Темы: Procedures and functions   

Alice studies symbolic graphics. First, she wanted to draw a right triangle with legs equal to 5. Write a triangle_down() routine for Alice to draw this triangle.

*
**
***
****
*****
Then, Alice wants to draw an inverted right triangle with legs equal to 5. Write Alice a subroutine triangle_up() to draw this triangle.
*****
****
***
**
*
After some thought, Alice decided that she could use your subroutines to draw the next shape. 
*****
****
***
**
*
*
**
***
****
*****

Write a subroutine star_figure() that would display this figure using the above subroutines. 
The main program should contain only one line - subroutine call star_figure().

 
Examples
# Input Output
1  
*****
****
***
**
*
*
**
***
****
*****

ID 42870. Right Triangle - 4
Темы: Procedures and functions   

Write a subroutine draw_figure(symbol, side) that draws a figure consisting of two isosceles right triangles (see examples).

Where

  • symbol - placeholder symbol that draws the shape;
  • side - the size of the legs of a right triangle.

Input
The first line contains a placeholder character (symbol), in the second line - the size of the legs (side) .

Imprint
Display the response shape.
 
Examples
# Input Output
1
*
5
*****
****
***
**
*
*
**
***
****
*****
2
x
3
xxx
xx
x
x
xx
xxx

ID 42871. Minimum Prime Divisor
Темы: Procedures and functions    Tasks for procedures and functions   

Alice knows that if a number n has no divisor less than or equal to\(\sqrt n\), then the number n is a prime number and its minimum prime divisor is the number itself n. You have been asked to write a program that will find the minimum prime divisor of any number.

Make your decision using functions. Write the following functions:
- the isPrime(n) function, which will take an integer and return True if the number is prime and False if it is not prime.
- minDivisor(n) function, which will return the minimum simple divisor.

The main program must contain a number input, a minDivisor(n) function call, and a response output.

Input
The program receives as input a natural number n > 1.

Imprint
Print the answer to the problem.
 

Examples
# Input Output
1 4 2
2 5 5

ID 42872. Access code
Темы: Procedures and functions    Tasks for procedures and functions   

Alice decided that she needed to put in an access code to control the ship. She believes that the access code should be of the form a:b:c, where a, b and c are integers. Moreover, the number a must be simple, the number b must be a palindrome, and the number c must be even. Captain Green came up with the code.

You've been given the task of writing a program that would print True if a given access code matches the rules and False if it doesn't. So that your program can be used for other checks, the captain asks you to issue a program using three functions:
- isPrime(n) - a function that determines whether the number n is prime or not;
- isPalindrome(n) - a function that determines whether the number n is a palindrome;
- isEven(n) - a function that determines whether the number n is even.

All checks of a number for primality, palindrome and evenness must be carried out only using these functions!

Input
The program receives one string as input - the access code that Captain Zeleny came up with.

Imprint
Print True if the access code matches Alice's rules, otherwise print False.
 

Examples
# Input Output
1 7:101:14 True
2 101:101:101 False
3 qwerty False