Light
Time limit2sMemory limit1024 MB
Given N bulbs and K divisors d_i, count the bulbs that are flipped an odd number of times.
- Level
Medium6 of 10
- Topics
- Combinatorics, Number theory, Bit manipulation
- Solved
- No attempts yet
Statement
In the physics lab, light bulbs are lined up in a row, numbered from 1 to . All bulbs are off at first. During class, each of the students picks an integer (). The student flips the state of every bulb whose number is a multiple of . A bulb that is on turns off, and a bulb that is off turns on. After flipping, the student leaves the room.
Write a program that counts the bulbs that are still on after all students have left.
Input
The first line contains the positive integer . The second line contains the number of students . The third line contains integers , separated by single spaces.
Output
Print a single line containing the number of bulbs that remain on after all students have left.
Constraints
- The numbers are not necessarily distinct
Hint
Initially, all the bulbs are off. After the first student flips the bulbs, the 2nd, 4th, 6th, and 8th bulbs are on. After the second student flips the bulbs, the 2nd, 3rd, 4th, and 8th bulbs remain on.