Math Problems: Geometry and Algorithms
Math Problems: Geometry and Algorithms
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
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
[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:
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.
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:
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.
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
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
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
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
[Link] 8/8