08Test1素数
2016-07-07 09:50
218 查看
<span style="font-family: Arial, Helvetica, sans-serif;">1.素数</span>
输入一个整数,要求输出所有从1到这个整数之间个位为1的素数,如果没有则输出-1(30分)
</pre><pre code_snippet_id="1749251" snippet_file_name="blog_20160707_1_8189551" name="code" class="html">
#include <stdio.h> #include <math.h> int main() { int n,i,j,index; int a[10001]; while(scanf("%d",&n)!=EOF) { index=0;//初始化重要!! for(i=11; i<n; i+=10) { int flag=1; for(j=2; j<=sqrt(i); j++) { if(i%j==0) { flag=0; break; } } if(flag==1) { a[index++]=i; } } if(index==0) { printf("-1\n"); } else { for(i=0; i<index-1; i++) { printf("%d ",a[i]); } printf("%d\n",a[index-1]); } } return 0; }
相关文章推荐
- IBM服务器IMM2升级微码
- android开发中,ListView中输入框与软键盘的坑
- 在整合spring+mybatis+Druid过程中出现的问题(java.sql.SQLException: validateConnection false和Unsupported major.m)
- 怎样学好C#编程
- 变压器型号、规格标识喷码机的优点。
- AI 《A PROPOSAL FOR THE DARTMOUTH SUMMER RESEARCH PROJECT ON ARTIFICIAL INTELLIGENCE》读后总结
- js第三天知识总结
- JsBridge "Uncaught TypeError: Cannot call method 'callHandler' of undefined", source
- 如何在 Ubuntu 15.04/CentOS 7 中安装 Lighttpd Web 服务器
- 算法复杂度
- directive
- 什么是嵌入式?嵌入式就业方向?需要具备的技能?
- 网页右侧悬浮广告
- 为什么要使用缓存?用OSCache提升J2EE系统运行性能
- 在MFC中对于位图的理解
- 专题四 · 1011
- Unity:iOS可执行程序超过80MB问题及各版本IL2CPP对比
- iOS App开发中的UIStackView堆叠视图使用教程
- 内存屏障
- Glide图片加载库的使用(一)