CodeForcesMaximum splitting(思路)

困惑了好久,还以为用dp,其实就是一道简单的思路题,如果通过观察发现,除了1 2 3 5 7 11不能被分解外,其它任何数,如果是偶数可以被分分解为4 或 6,如果是奇数可以分解为4或6或9。
通过计算发现,如果是偶数,那么最大的个数就是n/4,如果是奇数,因为多了一个9减去1即可。具体的数学原理,我也不太清楚,持续探索中。

打开方式不对,是很难找到出口的。

实现如下(题目附后)

#include <stdio.h>
int main() 
{
    int t,x;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&x);
        if(x<=3||x==5||x==7||x==11)  printf("-1\n");
        else  printf("%d\n", x/4-x%2);
    }
    return 0;
}

You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.

An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.

Input

The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries.

q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.

Output

For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.

Examples

扫描二维码关注公众号,回复: 5062046 查看本文章

Input

1
12

Output

3

Input

2
6
8

Output

1
2

Input

3
1
2
3

Output

-1
-1
-1

Note

12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.

8 = 4 + 4, 6 can't be split into several composite summands.

1, 2, 3 are less than any composite number, so they do not have valid splittings.

猜你喜欢

转载自blog.csdn.net/qq_43301061/article/details/86636790