[go: up one dir, main page]

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

LCPC CodeChef Training Contest

Uploaded by

sinyorinasoso.84
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)
6 views6 pages

LCPC CodeChef Training Contest

Uploaded by

sinyorinasoso.84
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

LCPC Training Contest – CodeChef Set

Duration: 4 hours

Number of Problems: 5

Rules:
- Solve the problems efficiently and correctly.
- Input/Output must follow the problem statement strictly.
- Standard input/output only.
- Time limit per problem: 1-2 seconds unless specified.
Problem A: Chef and Candies

Chef has N candies and wants to distribute them among K children equally. Determine whether Chef has enough
candies or how many more are needed.

Input:
- The first line contains two integers N and K.
Output:
Print 0 if Chef has enough candies, otherwise print the additional candies needed.

Constraints:
1 ≤ N ≤ 10^9, 1 ≤ K ≤ 10^5

Example:
Input
10 3
Output
2
Problem B: Chef and Strings

Given a string S, count the number of positions i (1 ≤ i < |S|) such that S[i] ≠ S[i+1].

Input:
- A single line containing string S (1 ≤ |S| ≤ 10^5, consisting of lowercase letters).
Output:
Print the number of adjacent unequal character positions.

Example:
Input
ababa
Output
4
Problem C: Chef and GCD

Given an array of N positive integers and an integer K, count the number of elements whose GCD with K is greater
than 1.

Input:
- First line: N and K
- Second line: N integers a1, a2, ..., aN
Output:
Print the count.

Constraints:
1 ≤ N ≤ 5000, 1 ≤ K ≤ 10^5, 1 ≤ ai ≤ 10^9

Example:
Input
5 12
6 7 13 24 25
Output
2
Problem D: Covid Spread Simulation

There is a population of N people. Each day, infected people infect exactly X new people. Initially, Y people are
infected. Compute the number of infected people after D days.

Input:
- One line: N, X, Y, D
Output:
Print the total infected after D days (cannot exceed N).

Constraints:
1 ≤ N ≤ 10^6, 0 ≤ X ≤ 100, 1 ≤ Y ≤ N, 1 ≤ D ≤ 1000

Example:
Input
100 2 1 3
Output
15
Problem E: Chef and Subarrays

Given an array of N integers, find the number of contiguous subarrays where the sum of elements equals the
product of elements.

Input:
- First line: N
- Second line: N integers a1, a2, ..., aN
Output:
Print the count of such subarrays.

Constraints:
1 ≤ N ≤ 1000, 1 ≤ ai ≤ 100

Example:
Input
3
221
Output
2

You might also like