TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">#include <stdio.h>
- #include <stdlib.h>
- /*
- 22. 已知 100个自然数 1~100,我们取 1, 2, 3, 4时,
- 我们可将其排成一圈使每两个数之和都是素数,即→1→2→3→4→,
- 问 1~100内连续取 n个数,即 1~ n(≤ 100)能满足上述要求的最大的 n是多少?
- */
- void main()
- {
- int a[100];
- int b[100]={0};
- int max=b[0];//定义b中的最大值
- for (int i=0;i<100;i++) // 开始给a赋初始值
- {
- a=i+1;
- }
- for (int i=0;i<100;i++)
- {
- int n=1;//存储n的数值
- int wei=i+1;
- for (int j=2;j<i+1;j++)
- {
- if ((a+a[i+1])%j!=0)
- {
- n++;
- if ((a[i+1]+a[i+1-n])%j!=0)
- {
- b=n;//将n存到数组b中
- }
- else
- {
- continue;
- }
- }
- }
-
- }
-
- for (int i=0;i<100;i++) /// 输出在b中记录的最大值
- {
-
- if (max<b)
- {
- max=b;
- }
- }
- printf("%d",max);
- system("pause");
- }</pre><br><br></pre>
|
|