A. Greatest Convex
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an integer k�. Find the largest integer x�, where 1≤x<k1≤�<�, such that x!+(x−1)!†�!+(�−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)!�!=�⋅(�−1)! for y≥1�≥1 with the base case of 0!=10!=1. For example, 5!=5⋅4⋅3⋅2⋅1⋅0!=1205!=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, 1010 is a multiple of 55 but 99 is not a multiple of 66.
Input
The first line contains a single integer t� (1≤t≤1041≤�≤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≤1092≤�≤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−1.
Example
input
Copy
4
3
6
8
10
output
Copy
2 5 7 9
Note
In the first test case, 2!+1!=2+1=32!+1!=2+1=3, which is a multiple of 33.
In the third test case, 7!+6!=5040+720=57607!+6!=5040+720=5760, which is a multiple of 88.
解题说明:此题是一道数学题,知道(n-1)!+(n-2)!=n! 这个公式就知道此题答案了。
#include <stdio.h>int main() {int t;scanf("%d", &t);while (t--) {int n;scanf("%d", &n);printf("%d\n", n - 1);}return 0;
}
A. Greatest Convex相关推荐
- A. Greatest Convex codeforces 1768A
Problem - A - Codeforces 题目大意:给出一整数n,求一整数k使得k!+(k-1)!能整除n 2<=k<=1e9; 思路:通过样例很容易发现结论就是k=n-1,因为k ...
- Codeforces Round #842 (Div. 2) 个人题解
A. Greatest Convex 题意: 给t组数据,每组数据给定一个k,求出在[1,k)范围内,满足x!+(x-1)!%k==0的最大x 题解: 赛中可以通过观察法得知输出k-1即可,赛后可以尝 ...
- R语言为散点图添加凸包(convex hull):数据预处理(创建一个包含每组数据凸包边界的数据集)、ggplot2使用geom_polygon函数为可视化图像添加凸包(convex hull)
R语言为散点图添加凸包(convex hull):数据预处理(创建一个包含每组数据凸包边界的数据集).ggplot2使用geom_polygon函数为可视化图像添加凸包(convex hull) 目录
- 转:Oracle greatest函数
格式: greatest( expr1, expr2, ... expr_n ) expr1, expr2, . expr_n 可以值也可以是函数. 函数功能: 取得值最大值. 影响版本: Oracl ...
- 实用线性代数和凸优化 Convex Optimization
If not specified, the following conditions are assumed. X∈Rn∗mA∈Rm∗nX \in R^{n*m} \\ A \in R^{m*n} X ...
- uva 10256 The Great Divide (Convex Hull, Simple)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=sh ...
- [2010山东ACM省赛] Greatest Number(数的组合+二分搜索)
Greatest Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya likes math, because ...
- UA MATH567 高维统计专题1 稀疏信号及其恢复2 用L1-norm作为L0-norm的convex relexation
UA MATH567 高维统计专题1 稀疏信号及其恢复2 用L1-norm作为L0-norm的convex relexation L1L_1L1-norm minimization L1L_1L1 ...
- 寻找凸包 (Convex Hull)
凸包问题是算法中经典的题目了,最近算法课讲分治问题时提到了Convex Hull,算法导论的书上也花了篇幅讨论了Convex Hull的求解,主要是Graham方法. 为了能更好地理解分治和Graha ...
最新文章
- 世界各大天文台联合预警:今晚公布“引力波重要发现”
- android 8 续航 评测,iPhone8续航能力测试 明显超过许多安卓手机
- OpenGl 绘制一个立方体
- 1030 Travel Plan (30 分) 【难度: 中 / 知识点: 最短路】
- [Everyday Mathematics]20150113
- bean创建异常_快速提示:消息驱动Bean中的异常处理
- linux——客户端服务器文件传输
- url动态追加参数_领高舆情优化:SEO网站URL优化的方法!
- asp.net 文件路径
- 关于 Java 字符串的全部,都在这份手册里了
- ccd视觉定位教程_CCD与CMOS哪个更能推动工业相机市场的发展
- 【经典算法】第八回:桶排序
- python zip dict_关于python:zip(list)和zip(* list)之间的区别
- USACO 2.1 海明码(DFS)
- Android 指南针校正
- 全键盘 linux 手机,当年青葱的岁月:10佳全键盘智能手机盘点
- CREO草绘标注字体设置
- 《给青年的十二封信》1-谈读书—朱光潜
- html 表情转换器,HTML5高仿微信聊天、微信聊天表情|对话框|编辑器功能
- android 输入法全屏,android 输入法不全屏
热门文章
- linux 不能开启443端口
- 12563 劲歌金曲
- windows10专业版 hyper-v
- 劫持流量原理是什么?关于劫持流量的种类和产生
- 计算机毕业设计Java网上书店管理系统(源码+系统+mysql数据库+Lw文档)
- char和varchar的区别
- Unity学习笔记 关于TextMeshPro(TMP) 字体大小FontSize单位说明
- java 月份缩写_Java常用日期、时间格式化转换符
- php mysql 聊天室_聊天室phpmysql(二)_php
- 什么是自然语言处理,自然语言处理目前的应用有哪些?