首页 > 数据库技术 > 详细

题解 【Cpdeforces755A】 PolandBall and Hypothesis

时间:2019-03-01 13:43:53      阅读:166      评论:0      收藏:0      [点我收藏+]

我们可以发现,当n>2时,n·(n-2)+1=(n-1)·(n-1),因此,输出n-2即可。

如果n<=2,我们可以发现:

  当n=2时,2·4+1=9不是质数,输出4即可;

  当n=1时,1·3+1=4不是质数,输出3即可。

至此,此题就被我们解决了!

AC代码:

 1 #include <bits/stdc++.h>//万能头文件
 2 
 3 using namespace std;//使用标准名字空间
 4 
 5 inline int read() { //快速读入
 6     int f=1,x=0;
 7     char c=getchar();
 8 
 9     while(c<0 || c>9) {
10         if(c==-)f=-1;
11         c=getchar();
12     }
13 
14     while(c>=0 && c<=9) {
15         x=x*10+c-0;
16         c=getchar();
17     }
18 
19     return f*x;
20 }
21 
22 int n,m;
23 
24 int main() {
25     n=read();//输入n
26 
27     if(n>2) { //如果n>2
28         printf("%d",n-2);//就输出n-2
29 
30         return 0;
31     }
32 
33     if(n==2) { //如果n=2
34         printf("4");//就输出4
35 
36         return 0;
37     }
38 
39     if(n==1) { //如果n=1
40         printf("3");//就输出3
41 
42         return 0;
43     }
44 
45     return 0;//结束
46 }

 

题解 【Cpdeforces755A】 PolandBall and Hypothesis

原文:https://www.cnblogs.com/xsl19/p/10455705.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!