Bags of Candies
Time limit2sMemory limit512 MB
Pair flavors 1 to n so that each shared bag has two flavors with a common divisor above 1, and find the fewest bags needed.
- Level
Medium7 of 10
- Topics
- Number theory, Greedy
- Solved
- No attempts yet
Problem
There are people who will not be happy solving a problem unless the actual task is hidden behind an elaborate and somewhat unnecessary story. If you are one of those people, this problem is for you.
As an Environment Specialist at a local candy factory, your life is sweet, both figuratively and literally. It is bound to get even sweeter. You were promised a promotion if you can halve the company's plastic footprint, and you plan to do exactly that.
Right now the factory uses huge amounts of plastic packaging. Every day it produces flavors of candy, numbered from 1 through , and each flavor goes into its own bag. Your idea is to pack two flavors per bag, which halves the number of bags.
It is not that simple. The -th flavor is always produced in quantity , and those candies are packed into one bag. If flavors and share a bag, the candies in that bag must be divided evenly and fairly among a group of friends of some size. Formally, and must have a common divisor greater than .
You can pair some flavors into shared bags and put the remaining flavors in their own bags. What is the least number of bags you need?
Input
The first line of input contains the number of test cases (). The descriptions of the test cases follow.
The only line of each test case contains a single number (), the number of flavors of candy produced at the factory.
Output
For each test case, output a single line containing the least number of bags needed.