D. K-good
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
We say that a positive integer nn is kk-good for some positive integer kk if nn can be expressed as a sum of kk positive integers which give kk distinct remainders when divided by kk.
Given a positive integer nn, find some k≥2k≥2 so that nn is kk-good or tell that such a kk does not exist.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1051≤t≤105) — the number of test cases.
Each test case consists of one line with an integer nn (2≤n≤10182≤n≤1018).
Output
For each test case, print a line with a value of kk such that nn is kk-good (k≥2k≥2), or −1−1 if nn is not kk-good for any kk. If there are multiple valid values of kk, you can print any of them.
Example
input
Copy
5 2 4 6 15 20
output
Copy
-1 -1 3 3 5
Note
66 is a 33-good number since it can be expressed as a sum of 33 numbers which give different remainders when divided by 33: 6=1+2+36=1+2+3.
1515 is also a 33-good number since 15=1+5+915=1+5+9 and 1,5,91,5,9 give different remainders when divided by 33.
2020 is a 55-good number since 20=2+3+4+5+620=2+3+4+5+6 and 2,3,4,5,62,3,4,5,6 give different remainders when divided by 55.

CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!) Editorial - Codeforces
相当于k1不满足条件的时候,k2是可行解
这里最初假定k是偶数,则k+1为奇数,这样k和(k+1)/2都不是n的因子,因为(k+1)/2不是整数
所以说当且仅当
2n=k (mod k)是显然成立的
说的不是很清楚
import sys
import math
#import numpy as np
from collections import defaultdict
#sys.stdin = open("in.txt", "r")
T = int(input())
for _ in range(T):
n = int(input())
k=1
while n%2==0:
n=n//2
k*=2
if n==1:
print('-1')
else:
print(min(n,2*k))
本文针对 Codeforces 的 D. K-good 问题提供了解决方案,该问题是关于判断一个正整数是否可以被表示为若干个能给出不同余数的正整数之和。文章详细解释了如何寻找合适的 k 值,并通过代码实现了解题思路。

被折叠的 条评论
为什么被折叠?



