Sets
Time limit1sMemory limit128 MB
Given n arithmetic-progression sets of multiples of d_i, count elements in their union that share no prime factor with m.
- Level
Hard9 of 10
- Topics
- Math, Number theory, Combinatorics, Intervals
- Solved
- No attempts yet
Problem
You are given sets. The -th set contains the numbers
Let be the union of all these sets. Count how many elements of are coprime with a given number (that is, whose greatest common divisor with equals ).
Input
The first line contains two integers and (, ).
Each of the next lines contains three integers , , separated by single spaces (, , ).
Output
Output a single integer: the number of elements of that are coprime with .