最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF 1768A - Greatest Convex

2023-07-01 09:56 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an integer k. Find the largest integer x, where 1≤x<k, such that x!+(x?1)!? is a multiple of ? k

, or determine that no such x exists.? y! denotes the factorial of y, which is defined recursively as y!=y?(y?1)!

?for y≥1 with the base case of 0!=1. For example, 5!=5?4?3?2?1?0!=120.

? If a and b are integers, then a is a multiple of b if there exists an integer c

?such that a=b?c. For example, 10 is a multiple of 5 but 9 is not a multiple of 6.


Input

The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows.

The only line of each test case contains a single integer k (2≤k≤109).

Output

For each test case output a single integer — the largest possible integer x that satisfies the conditions above.

If no such x exists, output ?1.

Is x=k?1 always suitable?


The answer is yes, as x!+(x?1)!=(x?1)!×(x+1)=((k?1)?1)!×((k?1)+1)=(k?2)!×(k)

, which is clearly a multiple of k

.


Therefore, x=k?1

?is the answer.


Time complexity: O(1)

一旦計算出來k-1是最大值,那么問題就很簡單了;

下面是代碼:


CF 1768A - Greatest Convex的評論 (共 條)

分享到微博請遵守國家法律
肥西县| 漠河县| 海丰县| 梁河县| 忻城县| 犍为县| 陇川县| 云霄县| 卓尼县| 比如县| 留坝县| 铜川市| 红河县| 临沂市| 肇源县| 阜城县| 康保县| 玛纳斯县| 恭城| 元谋县| 武川县| 阿图什市| 安岳县| 金乡县| 朝阳县| 盐山县| 蓝田县| 抚宁县| 古蔺县| 绥化市| 桓台县| 大城县| 新兴县| 广平县| 绥宁县| 哈巴河县| 莱阳市| 温宿县| 海林市| 霍林郭勒市| 平山县|