Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@senthil1185 | 90 |

@esmadhan | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Ishaan has been given a task by his teacher. He needs to find the Nth term of a series. His teacher gives him some examples to help him out (Refer examples below). He is a bit weak in pattern searching so to help him his teacher told him that the Nth term is **related to prime numbers**. The Nth term is the **difference of N and the closest prime number to N**. Help him find the Nth term for a given N.

**Input : **

The first line of input contains a single integer T denoting the number of test cases. Each test case contains an integer N.

**Output : **

For each test case, print the required answer in a new line.

**Constraints : **

1 <= T <= 200

1 <= N <= 10^6

**Note **: Constraints are high. Brute Force wont work.

**Example :
Input : **

6

1

2

3

10

15

26

1

0

0

1

2

3

**Explanation :**

Closest prime to 1 is 2. Difference = 2-1 = 1

Closest prime to 2 is 2. Difference = 2-2 = 0

Closest prime to 3 is 3. Difference = 3-3 = 0

Closest prime to 10 is 11. Difference = 11-10 = 1

Closest prime to 15 is 13. Difference = 15-13 = 2

Closest prime to 26 is 23. Difference = 26-23 = 3

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Help Ishaan

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.