| Author: | И. Блинов | Time limit: | 1 sec | |
| Input file: | Standard input | Memory limit: | 512 Mb | |
| Output file: | Standard output |
Let there be an infinite sequence of binary strings s[1], s[2], s[3], …. Each string is obtained as follows:
For each k, string s[k] is a concatenation of altering blocks of digits.
In particular:
The first 10 strings are:
0
10
010
1010
01011
101001
0101101
10100100
010110111
1010010001
Given an integer n find and output the string s[n].
The first line of the input contains a single integer n.
Output a single string of length n as described in the problem statement.
1 ≤ n ≤ 105
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| Author: | И. Блинов | Time limit: | 1 sec | |
| Input file: | Standard input | Memory limit: | 512 Mb | |
| Output file: | Standard output |
A badger is hiding in its complicated burrow, which is a long straight tunnel. The borrow is separated into N consecutive chambers, numbered 1 through N. The badger is very smart and sleeps in one of the chambers each night.
A team of two hunters learned about badger's habits and came up with a shrewd plan. Each night they will check the chambers with a certain step. In particular, on night i they check all the chambers with numbers divisible by Ai or Bi.
The badger will be caught if at least one hunter will check a chamber that it is sleeping in.
Your task is to find the number of safe chambers for the night i, i.e. chambers that the badger can sleep in without any of the hunters finding it.
The first line of the input contains two integers N and K — the number of chambers in the borrow and the number of nights.
The following K lines each contain two integers Ai, Bi — step size of each of the hunters.
Output K integers — numbers of safe chambers in the badger's borrow for each of the nights.
1 ≤ N ≤ 109, 1≤K≤104 1 ≤ Ai, Bi ≤ 109
| No. | Standard input | Standard output |
|---|---|---|
| 1 |
|
|
| 2 |
|
|