Functional Programming Answers

Questions: 109

Answers by our Experts: 81

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Simple Prime (Contest)

Time Limit: 2 sec

Memory Limit: 128000 kB

Problem Statement

Let's define P[i] as the ith Prime Number. Therefore, P[1]=2, P[2]=3, P[3]=5, so on.

Given two integers L, R (L<=R), find the value of P[L]+P[L+1]+P[L+2]...+P[R].

Input

The first line of the input contains an integer T denoting the number of test cases.

The next T lines contain two integers L and R.


Constraints

1 <= T <= 50000

1 <= L <= R <= 50000

Output

For each test case, print one line corresponding to the required value



Is this prime?

Problem Statement

Let's assume some functional definitions for this problem.

We take prime(x) as the set of all prime divisors of x. For example, prime(140)={2,5,7}, prime(169)={13}.


Let f(x,p) be the maximum possible integer p**k where k is an integer such that x is divisible by p**k.

(Here a**b means a raised to the power b or pow(a, b))

For example:

f(99,3)=9 (99 is divisible by 3**2=9 but not divisible by 3**3=27),

f(63,7)=7 (63 is divisible by 7**1=7 but not divisible by 7**2=49).


Let g(x,y) be the product of f(y,p) for all p in prime(x).

For example:

g(30,70)=f(70,2)*f(70,3)*f(70,5)=2*1*5=10,

g(525,63)=f(63,3)*f(63,5)*f(63,7)=9*1*7=63.

You are given two integers x and n. Calculate g(x,1)*g(x,2)*…*g(x,n) mod (1000000007).

(Read modulo exponentiation before attempting this problem)

Input

The only line contains integers x and n — the numbers used in formula.

Constraints

2 ≤ x ≤ 1000000000

1 ≤ n ≤ 1000000000000000000

Output

Print the answer corresponding to the input.



sprime

Time Limit: 2 sec

Memory Limit: 128000 kB

Problem Statement

Sara has developed a new algorithm to find sprime for a given range starting with 2


She will start from the end mark it sprime, and mark all its factors (excluding itself) as not sprime. Then she will find the next greatest unmarked number, mark it as sprime, and mark all its factors (excluding itself) as not sprime


Your task is to calculate the the number of sprimes that are actually prime

Input

The first line contains T the number of test cases.

Each of the next T lines contain an integer n.


Constraint:-

1 <= T <= 100

2 <= n <= 10000000

Output

Output T lines, one for each test case, containing the required answer.



Binary tree to double linked list

Problem Statement

Given a Binary Tree, your task is to convert it to a Doubly Linked List. The left and right pointers in nodes are to be used as previous and next pointers respectively in converted Double linked list. The order of nodes in Double linked list must be same as Inorder of the given Binary Tree. The first node of Inorder traversal (left most node in Binary tree) must be head node of the Doubly linked list.

Input

User Task:

Since this will be a functional problem. You don't have to take input. You just have to complete the function BToDLL() that takes "root" node of binary tree as parameter.


Constraint:-

1 <= Number of Nodes <= 1000

1 <= Node.data <= 1000

Output

The printing is done by the driver code you just need to complete the function.



Remove Duplicates from doubly linked list

Problem Statement

Given a sorted doubly linked list containing n nodes. Your task is to remove duplicate nodes from the given list.


Example 1:

Input

1<->2<->2-<->3<->3<->4


Output:

1<->2<->3<->4


Example 2:

Input

1<->1<->1<->1


Output

1

Input

User Task:

Since this will be a functional problem, you don't have to take input. You just have to complete the function deleteDuplicates() that takes head node as parameter.


Constraints:

1 <=N <= 10000

1 <= Node. data<= 2*10000

Output

Return the head of the modified list.




Camp Setup (Contest)

Time Limit: 2 sec

Memory Limit: 128000 kB

Problem Statement

Given N points on 2D plane, you have to setup a camp at a point such that sum of Manhattan distance all the points from that point is minimum. If there are many such points you have to find the point with minimum X coordinate and if there are many points with same X coordinate, you have to minimize Y coordinate.

Manhattan distance between points (x1, y1) and (x2, y2) = |x1 - x2| + |y1 - y2|.

Input

First line of input contains N.

Next N lines contains two space separated integers denoting the ith coordinate.


Constraints:

1 <= N <= 100000

1 <= X[i], Y[i] <= 1000000000

Note:- the camp can overlap with the given points and the given points can also overlap(you have to consider overlapping points separately).

Output

Print two space separated integers, denoting the X and Y coordinate of the camp.

Example

Sample Input

3

3 3

1 1

3 2


Sample Output

3 2



Why cyber security is important?


Answer in bulleted list - What are the benefits and applications of information technology?


Create a class called Match that will have team objects and be used for creating a Match of play; the class must have the following data members and methods:

 

Data Members:

•       This class has two data members named HomeTeam and VisitorTeam which are of type Team, they will store that two teams that will play the Match.

Methods:

•       This class doesn’t have a default constructor, it only has one constructor which receives two Team object that will be assigned to HomeTeam and VisitorTeam.

•       setTeams(),which receives two Team object that will be assigned to HomeTeam and VisitorTeam.

•       playMatch(), simulates match play by calling the scoreGoals methods of each team.

•       getPlayGound(), returns the ground of play which is the HomeGound of the HomeTeam.

•       isDrawMatch(), will return true if the Match is a draw and false if there is a winner. The match is a draw if the goals of the teams are equal.

•      



2. Valaqa wants to put together a computer. She was told to estimate a proper supply for the build. She was told every drive consumes 50W and she wants 3 installed. Additionally, her CPU of choice consumes 180W. Video card and remaining components add up to 300W of power consumption. She was told to plan the PSU capacity with some spare. What rating of PSU would you recommend to Valaqa, so that all the criteria mentioned before is met. Recommend 2 brands and justify your recommendations.


LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS