C#找出第n到m个素数之间所有之和
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine()); //开始的数
int m = int.Parse(Console.ReadLine()); //结束的数
int sun = ; //累加
int count = ; //素数
bool flag=true; //判断是否为素数 true 是素数 false不是素数
for (int i = ; count < m; i++)
{
for (int j = ; j < i; j++)
{
//如果可以被整除一定不是素数
flag = i % j == ? flag = false : flag = true;
break;
//if (i % j == 0) //判断不是素数
//{
// flag = false;
// break;
//}
}
if (flag)
{
count++; //如果是素数自增+1
if (count >= n && count <= m)
{
Console.WriteLine("素数是:" + i);
sun += i;
}
}
flag = true; }
Console.WriteLine(sun);
Console.ReadKey();
}
C#找出第n到m个素数之间所有之和的更多相关文章
- 程序使用嵌套的for循环找出2〜100中的素数
#import <Foundation/Foundation.h> int main () { /* local variable definition */ int i, j; ; i& ...
- Entity Framework 6 Recipes 2nd Edition(9-3)译->找出Web API中发生了什么变化
9-3. 找出Web API中发生了什么变化 问题 想通过基于REST的Web API服务对数据库进行插入,删除和修改对象图,而不必为每个实体类编写单独的更新方法. 此外, 用EF6的Code Fri ...
- 使用T-SQL找出执行时间过长的作业
有些时候,有些作业遇到问题执行时间过长,因此我写了一个脚本可以根据历史记录,找出执行时间过长的作业,在监控中就可以及时发现这些作业并尽早解决,代码如下: SELECT sj.name , ...
- [LeetCode] Find All Numbers Disappeared in an Array 找出数组中所有消失的数字
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- [LeetCode] Find All Duplicates in an Array 找出数组中所有重复项
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others ...
- [LeetCode] Find Median from Data Stream 找出数据流的中位数
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- 如何找出标有"App Store 精华","Essentials"的所有软件?
如何找出标有"App Store 精华","Essentials"的所有软件? 中国区: +"App Store 精华" site:http ...
- 在一个SQL Server表中的多个列找出最大值
在一个SQL Server表中一行的多个列找出最大值 有时候我们需要从多个相同的列里(这些列的数据类型相同)找出最大的那个值,并显示 这里给出一个例子 IF (OBJECT_ID('tempdb..# ...
- 在数组中找出x+y+z=0的组合
就是找x+y=-z的组合 转化为找出值为-z满足x+y=-z的组合 解法一: 为了查找,首先想到排序,为了后面的二分,nlogn, 然后x+y的组合得n^2的复杂度,加上查找是否为-z,复杂度为nlo ...
随机推荐
- MAC JDK默认安装路径 JAVA路径
打开终端,执行 /usr/libexec/java_home -V 默认JDK1.6(Apple自带JDK)路径: /System/Library/Java/JavaVirtualMach ...
- delphi Int64Rec 应用实例
以下代码可以看到 Int64Rec <--> Int64 procedure TForm1.Button2Click(Sender: TObject); var ii1,ii2,ii3:I ...
- 黄聪:jquery+Datatables出现数据过长,表格不自动换行,columns设置width失效的办法
添加下面的CSS代码即可: table.dataTable.nowrap th, table.dataTable.nowrap td{white-space: normal !important;}
- html json 导出Excel
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- bzoj 4866: [Ynoi2017]由乃的商场之旅
设第i个字母的权值为1<<i,则一个可重集合可以重排为回文串,当且仅当这个集合的异或和x满足x==x&-x,用莫队维护区间内有多少对异或前缀和,异或后满足x==x&-x,这 ...
- Null hypothesis TypeⅠerror Type Ⅱ error
Null hypothesis usually express the phenomenon of no effect or no difference. TypeⅠerror is the inco ...
- P2064进制转换
题目:https://www.luogu.org/problemnew/show/P2084 既然这道题放在字符串类型里,那么这里的N肯定得用字符数组来储存(这样也方便输出). 那么我们不妨定义一个字 ...
- Java学习——加法器
package cys; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.aw ...
- 学习笔记之Git / Gitflow / TortoiseGit
Git - Wikipedia https://en.wikipedia.org/wiki/Git Git (/ɡɪt/) is a version control system for tracki ...
- win server 2008 R2 安装IIS
IIS是基于windows系统的一个互联网信息服务,可以使用IIS创建网站.FTP站点等服务. 安装IIS 打开服务器管理器,角色,添加角色 下一步 选择"Web服务器(IIS)" ...