C - Present Students

Description:

A professor is teaching a class that has \(n\) students that are numbered \(1, 2, \dots, n\). The professor started noticing a pattern in how students attend the class. Assuming 0 indicates a student is absent and 1 indicates a student is present, the students come to class everyday in the following patterns:

  • The first student's pattern is \(1010101010101010\dots\)
  • The second student's pattern is \(1100110011001100\dots\)
  • The third student's pattern is \(111000111000111000\dots\)
  • The fourth student's pattern is \(1111000011110000\dots\)
  • The fifth student's pattern is \(11111000001111100000\dots\)

and so on.

Given a number of students \(d\) and a day \(d\), your task is to determine the number of present students?

Program Input:

A single line that contains two integers \(n\) and \(d\), the number of students and the specified day.

Constraints:

\(1 \leq n \leq 10^4\)

\(1 \leq d \leq 10^6\)

Program Output:

A single line contains how many students will be present at day \(d\).

Sample Testcase 0:

Input:

4 10

Output:

2

Explanation:

Only the second and fourth students will be present.

  • The first student's pattern for the first ten days is \(1010101010\)
  • The second student's pattern for the first ten days is \(1100110011\)
  • The third student's pattern for the first ten days is \(1110001110\)
  • The fourth student's pattern for the first ten days is \(1111000011\)

Sample Testcase 1:

Input:

100 1

Output:

100

Explanation:

All students will be present on the first day.


CodeBox

Information

Author(s) Dr. Fahed Jubair
Deadline No deadline
Submission limit No limitation

Sign in