0% found this document useful (0 votes)
244 views6 pages

Mathematics Problems

The document discusses several topics related to TA sessions: 1. It provides an approach and proof for enumerating the greatest common divisor (GCD) for problem 4. 2. It asks about explaining the divisor game problem and provides constraints for problem 3. 3. It asks for an explanation of why the solution to problem 3 divides A by B * C/GCD(B,C) instead of just A / (B * C). 4. It discusses repeated subtraction for finding the GCD and explains that the numbers will reduce to their GCD, but the given solution has high time complexity.

Uploaded by

ankit damseth
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)
244 views6 pages

Mathematics Problems

The document discusses several topics related to TA sessions: 1. It provides an approach and proof for enumerating the greatest common divisor (GCD) for problem 4. 2. It asks about explaining the divisor game problem and provides constraints for problem 3. 3. It asks for an explanation of why the solution to problem 3 divides A by B * C/GCD(B,C) instead of just A / (B * C). 4. It discusses repeated subtraction for finding the GCD and explains that the numbers will reduce to their GCD, but the given solution has high time complexity.

Uploaded by

ankit damseth
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
You are on page 1/ 6

TA Session

Approach for 4th problem: enumerating GCD

Proof: We know that if a number D divides both A and B, it will also divide
abs(A-B)
Now, if B = A+1, let's assume D to be a number that divides both
A and B.
D should also divide abs(A-B) = abs(A - (A+1)) = 1
But the only number to perfectly divide 1 is 1 itself, hence D has
to be 1

3rd problem?:Divisor game

Divisor game 
Scooby has 3 three integers A, B and C.​ ​Scooby calls a positive integer special if it is 
divisible by B and it is divisible by C. You need to tell number of special integers less 
than or equal to A.​ C
​ onstraints: 
1<=A,B,C<=1000000000

Input: 
A positive integer A
A positive integer B
A positive integer C
Examples:​ I​ nput: 

12

2
Output: 

Explanation:  

The two integers divisible by 2 and 3 and less than or equal to 12 are 6,12.

int gcd(int a, int b){

if(b == 0) return a;

return gcd(b, a % b);

int Solution::solve(int A, int B, int C) {

return A / ( B * C / gcd(B, C ));

Can you explain why its not A / ( B * C )?

 
 
Repeated Subtraction(time complexity) 
 
Observe that finally the numbers will reduce to their gcd (can be proven 
mathematically) 
 
My solution: 
 
int Solution::getFinal(int A, int B) { 
if(A==B) 
return A+B; 
else if(A==0 || B==0) 
return A+B; 
if(B>A) 

  swap(A,B); 
  if(A%B==0) 
  return B*2; 

int temp=__gcd(A,B); 
return temp; 

It is getting not completed in given time  
Time complexity is high 
For the above solution efficiency is not their as shown when submitted 
Partially Correct Answer. 
You got 100.0/200 points! 
ok 
 
 
Q Max Chunks To Make Sorted II 
Yesterday Homework 
Can you explain this? 
 
https://leetcode.com/articles/max-chunks-to-make-sorted-ii/ 
 
 
 
Merge Intervals 
Given a set of non-overlapping intervals, insert a new interval into the intervals 
(merge if necessary).​ Y ​ ou may assume that the intervals were initially sorted
according to their start times​.​ E ​ xample 1:​ ​Given intervals [ ​ 1,3],[6,9]​ insert and 
merge ​[2,5]​ would result in [ ​ 1,5],[6,9]​.​ E​ xample 2:​ ​Given 
[1,2],[3,5],[6,7],[8,10],[12,16]​, insert and merge [ ​ 4,9]​ would result in 
[1,2],[3,10],[12,16]​.​ T ​ his is because the new interval ​[4,9]​ overlaps with 
[3,5],[6,7],[8,10]​.​ M ​ ake sure the returned intervals are also sorted. 
Sir pls provide some hints to solve it.  
 
[1, 3] 
[2, 5] 
[6, 9] 
 
Max Chunks To Make Sorted II 
Given an array of integers (not necessarily distinct) A
​ ​, if we split the array into some 
number of "chunks" (partitions), and individually sort each chunk. After 
concatenating them, the result equals the sorted array. 
Input 1:
A = [3, 2, 3, 4, 0]
Output 1:
1

Input 2:
A = [2, 0, 1, 2]
Output 2:
2

Sir give hints

Does anyone has solved it provide some hints ??

https://leetcode.com/articles/max-chunks-to-make-sorted-ii/

Sub-matrix Sum Queries 


Given a matrix of integers A
​ ​ of size N
​ x M​ and multiple queries ​Q,​ for each query find 
and return the submatrix sum.​ I​ nputs to queries are ​top left (b, c)​ and ​bottom right (d, 
e)​ indexes of submatrix whose sum is to find out.​ ​Note:​ Rows are numbered from 
top to bottom and columns are numbered from left to right. Sum may be large so 
return the answer mod 1 ​ 0^9 + 7​.  

Input Format 
The first argument given is the integer matrix A.
The second argument given is the integer array B.
The third argument given is the integer array C.
The fourth argument given is the integer array D.
The fifth argument given is the integer array E.
(B[i], C[i]) represents the top left corner of the i'th query.
(D[i], E[i]) represents the bottom right corner of the i'th query.

Output Format 
Return the submatrix sum (% 10^9 + 7) for each query in the form of an integer array.
Constraints 
1 <= N, M <= 1000
-100000 <= A[i] <= 100000
1 <= Q <= 100000
1 <= B[i] <= D[i] <= N
1 <= C[i] <= E[i] <= M

For Example 
Input 1:
A = [ [1, 2, 3]
[4, 5, 6]
[7, 8, 9] ]
B = [1, 2]
C = [1, 2]
D = [2, 3]
E = [2, 3]
Output 1:
[12, 28]

Input 2:
A = [ [5, 17, 100, 11]
[0, 0, 2, 8] ]
B = [1, 1]
C = [1, 4]
D = [2, 2]
E = [2, 4]
Output 2:
[22, 19]

   
 
Yes sir got it but i have raised doubt raju sir didn’t ans ? there is no option  
Okay sir thank you sir 
 
 
 
 
 
 
 
 
 
 
 

You might also like