0% found this document useful (0 votes)
46 views8 pages

Math Problems: Geometry and Algorithms

The document outlines a series of programming problems related to mathematics and geometry, each with specific input and output requirements. Problems include determining if a number is a power of two, checking for prime numbers, calculating sums and products, and working with matrices and divisibility. Each problem includes constraints and examples to guide implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views8 pages

Math Problems: Geometry and Algorithms

The document outlines a series of programming problems related to mathematics and geometry, each with specific input and output requirements. Problems include determining if a number is a power of two, checking for prime numbers, calculating sums and products, and working with matrices and divisibility. Each problem includes constraints and examples to guide implementation.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9/25/25, 11:17 PM Problems - Codeforces

Sheet #6 (Math - Geometry)

A. Power Of Two summation of even numbers between A and B (inclusive).


summation of odd numbers between A and B (inclusive).
1 second, 256 megabytes
Input
Given a number N . Determine whether N is power of 2 or not. Only one line contains two numbers A and B (1 ≤ A, B ≤ 109).

Input Output
Only one line contains a number N (1 ≤ N ≤ 10
18
) . Print the answer required above.

Output input
Print "YES" if N is power of 2 otherwise, print "NO".
4 6

input output
8 15
10
output 5
YES
input
input 7 1
10 output
output 28
12
NO
16

B. Prime checking D. Xor


4 seconds, 256 megabytes
1 second, 256 megabytes
Given a number N. Determine whether N is Prime or Not. Given three numbers A , B and Q. Determine the value of the Qth
Input element using the formula below:
Only one line contains a number N (1 ≤ N ≤ 1012).

Output
Print "YES" if N is Prime otherwise, print "NO".

input
2
Input
output Only one line contains three numbers A , B and Q
12
YES (1 ≤ A, B, Q ≤ 10 ) .

Output
input
Print the value of the Qth element.
1007

output input
NO 5 3 1

output
input 5
12

output input
NO 5 3 2

output
C. Sum of Range 3

0.5 seconds, 256 megabytes


input
Given 2 numbers A and B. Print three lines that contain the following 5 3 3
respectively: output
summation of all numbers between A and B (inclusive). 6

[Link] 1/8
9/25/25, 11:17 PM Problems - Codeforces
In c++ to use xor operator you may write : input
int x = a ^ b; 2 2
1 2
but if you need to print a ^ b 2 1
2 2
you should write 3 4
4 3
cout « (a ^ b);
output
11 10
E. Maximum Distinct Numbers 10 11
1 second, 64 MB
For more information visit Matrix Multiplication:
Given a number N . Print the maximum number of distinct numbers that
[Link]
their summation is less than or equal to N .

Input
Only one line contains a number N (1 ≤ N ≤ 10
18
) .
G. Summation of its divisors
1 second, 256 megabytes
Output
Print the required answer above. Given a number N. Print the Summation of its divisors.

input Input
Only one line contains a number N (1 ≤ N ≤ 1012).
15

output Output
Print the answer required above.
5

input
input
12
8
output
output
28
3

input
In the first example:
9
1+2+3+4+5 equal 15 which is ≤ N .
output
In the second example:
13
1+2+3 equal 6 which is ≤ N .
In the first example:

F. Multiplication of Matrices The divisors of 12 are [1, 2, 3, 4, 6, 12].

1 second, 256 megabytes Then the result will be 1 + 2 + 3 + 4 + 6 + 12 = 28.

Given two matrices A and B. Print their Multiplication.


H. GCD
Input 1 second, 256 megabytes
First line contains two numbers RA and CA (1 ≤ RA, CA ≤ 100) number
of rows and number of columns respectively of Matrix A. Given two numbers A and B. Print the GCD and LCM of A and B.

Next RA lines will contain CA numbers ( - 100 ≤ Ai, j ≤ 100) Matrix A Note:
numbers.
GCD is the greatest common divisor of A and B.
Next line will contain two numbers RB and CB (1 ≤ RB, CB ≤ 100)
LCM is the least common multiple of A and B.
number of rows and number of columns respectively of Matrix B.

Next RB lines will contain CB numbers ( - 100 ≤ Bi, j ≤ 100) Matrix B


Input
Only one line contains two numbers A and B (1 ≤ A, B ≤ 2 * 109).
numbers.

It's guaranteed that number of columns in the matrix A is equal to Output


Print the GCD and the LCM of A and B separated by a space.
number of rows in the matrix B.

Output input
Print the Multiplication result.
12 18

output
6 36

[Link] 2/8
9/25/25, 11:17 PM Problems - Codeforces
For more information about GCD visit : input
[Link]
1299721
For more information about LCM visit :
output
[Link]
(1299721^1)

I. Divisability
K. Combination and Permutation
0.25 seconds, 64 megabytes
1 second, 256 megabytes
Given three numbers A, B and X. Print the summation of numbers
between A and B inclusive that are divisible by X. Given two numbers A and B . Print NCR and NPR of A and B .

Input Note:
Only one line contains three numbers A, B and X
NCR is the Combination.
(1 ≤ A, B ≤ 109, 1 ≤ X ≤ 109).
NPR is the Permutation.
9
It's guaranteed that (0 ≤ |A - B| < 10 ).
Input
Output Only one line contains two numbers A and B (0 ≤ A, B ≤ 19) .
Print the answer required above.
It's guaranteed that A ≥ B .
input Output
5 20 5 Print NCR and NPR of A and B separated by a space.

output
input
50
5 3

input output
3 12 3 10 60

output
input
30
6 2
In the first example: output
The numbers [5, 10, 15, 20] are dividable by 5 then the result: 5 + 10 + 15 15 30
+ 20 = 50.
For more information visit:

J. Prime Factors [Link]


[Link].
1 second, 256 megabytes

Given a number N. Print the prime factors of N in the following form: (P1)x
y z L. Pascal Triangle
* (P2) * (P3) * ...
1 second, 256 megabytes
Note: P1, P2, ..., Pi are prime factors of N.
Given a number N . Print first N rows of pascal triangle.
For example:
Input
If N = 1260: 1260 = 2*2*3*3*5*7 then print (2^2)*(3^2)*(5^1)*(7^1).
Only one line contains a number N (1 ≤ N ≤ 30) .
Input Output
7
Only one line contains a number N (2 ≤ N ≤ 2 * 10 ). Print first N rows of pascal triangle.
Output
x y z
Print N in this form (P1) * (P2) * (P3) * ... input
3
input output
1260
1
output 1 1
1 2 1
(2^2)*(3^2)*(5^1)*(7^1)

input
input
4
1677060

output
(2^2)*(3^2)*(5^1)*(7^1)*(11^3)

[Link] 3/8
9/25/25, 11:17 PM Problems - Codeforces

output input
1 2
1 1 5 2
1 2 1
1 3 3 1 output
For more information visit pascal triangle: 101

[Link] .
O. Big Add and Multiply
M. Divisible 1 second, 256 megabytes
1 second, 256 megabytes Given a number N . Print N + 9999 and N * 9999.

Given two numbers N and X. Determine whether N is divisible by X or Input


not. Only one line contains a number N (1 ≤ N ≤ 10
10000
.
)

Input Output
Only one line contains two numbers N and X Print two lines contain N + 9999 and N * 9999 respectively.
10000 9
(0 ≤ N ≤ 10 , 1 ≤ X ≤ 10 ) .
input
Output
Print "YES" if N is divisible by X otherwise, print "NO". 1

output
input
10000
15 3 9999

output
input
YES
10

input output
10 7 10009
99990
output
NO
P. Factorial Digits
N. Convert to Base 1 second, 256 megabytes

1 second, 256 megabytes Given a number N . Print the number of digits of N !.

Given three numbers T , N and X. Input


Only one line contains a number N
5
(1 ≤ N ≤ 10 ) .
If T = 1 then Convert N from base X to decimal.
If T = 2 then Convert N from decimal to base X. Output
Print one line that contains the following respectively:
Note: As X may exceed base 10 then the number N can contain digits
1. "Number of digits of " + N + "! is " + the number of digits.
from 0 to 9 and from A to Z. Such that Value of A = 10, value of B = 11
and so on.
input
Input 5
First line contains a number T (1 ≤ T ≤ 2) type of conversion.
output
Second line contains two numbers N and X :
Number of digits of 5! is 3
If T = 1 then (1 ≤ |N | ≤ 10, 2 ≤ X ≤ 35) where |N| is length of
In the first example:
number.
If T = 2 then (1
9
≤ N ≤ 10 , 2 ≤ X ≤ 35) . 5! = 5*4*3*2*1 = 120.

Output And 120 has 3 digits.


Print the answer required above.
Q. Product
input
1 second, 256 megabytes
1
101 2
Given three numbers L,R and M . Print the product of all numbers from
output L to R (inclusive) module M .

5 Input

[Link] 4/8
9/25/25, 11:17 PM Problems - Codeforces
Only one line contains three numbers L, R and M input
5
(1 ≤ L, R, M ≤ 10 ) .
3 4 1
It's guaranteed that (L ≤ R). output
Output
Invalid
Print the answer required above.
Your answer will be considered correct if its absolute or relative error does
input not exceed 10 - 4 .

1 20 10007

output T. Circle Task


8707 1 second, 64 megabytes

Given a cartesian point (X, Y) donates a circle center, a number R


R. Distance points donates radius of the circle and a number N donates number of points
coordinates. For each point determine whether it belongs to the circle or
1 second, 256 megabytes
not.
Given 2 Cartesian points (X1, Y1) and (X2, Y2). Print the distance Input
between the two points. First line contains four numbers X, Y, R and N
Input ( - 109 ≤ X, Y ≤ 109, 1 ≤ R ≤ 109, 1 ≤ N ≤ 100).
Only one line contains four numbers X1, Y1, X2 and Y2 Next N lines will contain one point (xi, yi) ( - 109 ≤ xi, yi ≤ 109).
(1 ≤ X1, Y1, X2, Y2 ≤ 109).
Output
Output For each N lines print "YES" if the ith point belongs to the circle and "NO"
Print the answer required above. otherwise.

input input
5 3 22 11 0 0 4 5
output 1 3
4 5
18.788294228 4 0
0 0
5 2
input
2 3 1 1
output
YES
output NO
2.236067977 YES
YES
Your answer will be considered correct if its absolute or relative error does NO

not exceed 10 - 6.
U. Straight Line
S. Is Triangle 1 second, 256 megabytes
1 second, 256 megabytes
Given three points on the Cartesian plane. Determine whether a single
Given three numbers A, B and C that donate the lengths of the three straight line can pass through these points or not.
sides of a triangle. Determine whether this triangle is valid or not and if it
Input
is valid print its area.
First line contains two numbers X1 , Y1
5 5
(−10 ≤ X1 , Y 1 ≤ 10 ) .
Input
Second line contains two numbers X2 , Y2
5 5
(−10 ≤ X2 , Y 2 ≤ 10 ) .
Only one line contains three numbers A, B and C (1 ≤ A, B, C ≤ 103).
Third line contains two numbers X3 , Y3
5 5
(−10 ≤ X3 , Y 3 ≤ 10 ) .
Output
If the three sides preform a triangle print "Valid" and the area of the Output
triangle in separate lines otherwise, print "Invalid". Print "YES" if a single straight line can pass through the three points
otherwise, print "NO".
Don't print any extra spaces.

input
input
1 1
7 10 5
2 2
output 3 3

Valid output
16.248077 YES

[Link] 5/8
9/25/25, 11:17 PM Problems - Codeforces

input input
0 1 0 0 6 0
-4 7 -8 7 -12 2
3 3
output
output
NO
NO

X. Rectangle
V. Two Lines
1 second, 256 megabytes
1 second, 256 megabytes
Given a rectangle represented by four distinct points:
Given two lines L1 and L2, Determine whether they are parallel or not. (x 1 , y1 ), (x 2 , y2 ), (x 3 , y3 ) and (x 4 , y4 ) ,With two sides parallel to the Y-

axis and the other two parallel to the X-axis and N points, for each point
Input
check whether it belongs to the rectangle or not.
First line contains four numbers (X1 , Y1 ), (X2 , Y2 )
4 4
(−10 ≤ X1 , Y 1 , X2 , Y 2 ≤ 10 ) which denote start and end point of Input
L1 respectively. First line contains x 1 , y1 , x 2 , y2 , x 3 , y3 , x 4 and y4 ,
5 5

Second line contains four numbers (X3 , Y3 ), (X4 , Y4 ) (−10 ≤ x 1 , y1 , x 2 , y2 , x 3 , y3 , x 4 , y4 ≤ 10 ) .


4 4
(−10 ≤ X3 , Y 3 , X4 , Y 4 ≤ 10 ) which denote start and end point of Second line contains N , (1 ≤ N ≤ 10) .
L2 respectively.
Next N lines will contain one point (x i , yi ), (−10
5 5
≤ x i , yi ≤ 10 ) .
Output
Print "YES" if the two lines are parallel otherwise, print "NO". Output
For each N lines print "YES" if the ith point belongs to the rectangle and
input "NO" otherwise.

1 1 10 1
1 2 10 2
input
0 0 0 2 2 0 2 2
output 3
YES 1 1
1 5
0 0
input
output
10 0 0 10
0 0 10 10 YES
NO
output YES
NO

Y. Common Area
W. Circles 1 second, 256 megabytes
1 second, 256 megabytes
Given N rectangles, each rectangle will be represented as two points: the
Given four cartesian points (X1 , Y1 ), (X2 , Y2 ), (X3 , Y3 ) and (X4 , Y4 ) lower-left point (x 1 , y1 ) and the upper right point (x 2 , y2 ) .
that donate two endpoints of a diameter of circle A and circle B
Determine the common area shared between all rectangles.
respectively. Determine whether these two circles intersect or not.
Input
Input First line contains a number T (1 ≤ T ≤ 100) number of test cases.
First line contains four numbers (X1 , Y1 ) and (X2 , Y2 )
(−10
5 5
≤ X1 , Y 1 , X2 , Y 2 ≤ 10 ) two endpoints of a diameter of the Each test described by a number of rectangles N (1 ≤ N ≤ 30) .
circle A . Next N lines will contain 4 integers x 1 , y1 , x 2 and y2
4 4
Second line contains four numbers (X3 , Y3 ) and (X4 , Y4 ) (−10 ≤ x 1 , y1 , x 2 , y2 ≤ 10 ) .
5 5
(−10 ≤ X3 , Y 3 , X4 , Y 4 ≤ 10 ) two endpoints of a diameter of the It's guaranteed that all rectangle sides are parallel to Ox or Oy axes.
circle B .
Output
Output For each test case output "Case #i: a". Where i is a test number, and a is
Print "YES" if circle A intersect circle B otherwise, print "NO". the area shared between all rectangles.

input input
1 2 1 -2
1
4 3 1 0
4
output 0 0 10 10
-1 -1 2 2
YES -10 0 2 100
-10 -10 10 10

[Link] 6/8
9/25/25, 11:17 PM Problems - Codeforces

output
Case #1: 4

Z. Geometry Test
1 second, 256 megabytes

Given two numbers R and S that donate radius of a circle and side length
of a square. Determine which shape holds the other or it's complex to be
determined.

Input
Only one line contains two number R and S
6
(1 ≤ R, S ≤ 10 ) a radius
of a circle and the side length of a square.

Output
Print "Circle" if the square is drawn inside the circle, "Square" if the circle
is drawn inside the square and "Complex" otherwise.

input
5 6

output
Circle

input
3 8

output
Square

input
5 8

output
Complex

[Link] 7/8
9/25/25, 11:17 PM Problems - Codeforces

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform

[Link] 8/8

You might also like