hdu2161 Primes
2016-01-17 15:58
246 查看
#include <stdio.h>
#include <string.h>
#include <math.h>
int is_prime(int n)
{
if(n <= 1) return 0;
int m = floor(sqrt(n) + 0.5);
for(int i = 2; i <= m; i++)
if(n % i == 0) return 0;
return 1;
}
int main()
{
int num, kase;
kase = 1;
while(~scanf("%d", &num) && (num > 0))
{
if(!is_prime(num) || (num == 2)) printf("%d: no\n",kase++);
else printf("%d: yes\n",kase++);
}
return 0;
}
心得: The list of integers is terminated with a number<= 0.....真是瞎了我的狗眼,还wa了一次
#include <string.h>
#include <math.h>
int is_prime(int n)
{
if(n <= 1) return 0;
int m = floor(sqrt(n) + 0.5);
for(int i = 2; i <= m; i++)
if(n % i == 0) return 0;
return 1;
}
int main()
{
int num, kase;
kase = 1;
while(~scanf("%d", &num) && (num > 0))
{
if(!is_prime(num) || (num == 2)) printf("%d: no\n",kase++);
else printf("%d: yes\n",kase++);
}
return 0;
}
心得: The list of integers is terminated with a number<= 0.....真是瞎了我的狗眼,还wa了一次
相关文章推荐
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- 2015-11-11 hdu新生赛 A题(AC)
- 2015-11-11 hdu新生赛 C题(结束后一发AC)
- 2015-11-11 hdu新生赛 E题(结束后一发AC)
- 2015-11-11 hdu新生赛 F题(结束后一发AC)
- hdu-5385