- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
1 素数之和
题目:求出【m,n】之间(包括m和n),所有素数之和。
输入:有若干组测试数据,每组一行,每行两个整数m、n,2=m=n=100000。
输出:每行输出一个整数,对应输入数据,表示素数之和
1 Sum of prime numbers
Find the sum of the prime numbers between m and n(include m and n).
There are some groups of test data, each group is in one line, and in each line there are two integers m and n, 2=m=n=100000.
Output an integer in each line after input data to represent the sum of prime numbers,
样例输入:
2 2
2 3
4 10
样例输出:
2
5
12
答案:
#includemath.h
#includestdio.h
int f[100000]={0};//全局数组存标志,当f[i]==0时,i是素数
int sum[100000]={0};//全局数组存部分和,sum[i]存【2,i】之间所有素数之和
void set()
{
int i,j,s=0;
//筛选法求素数,设置数组f
for( i=2;i=sqrt(100000);i++)
if(f[i]==0)
for(j=2*i;j100000;j+=i)
f[j]=1;
//设置数组sum以便查询
for( i=2;i100000;i++)
{ if(f[i]==0) s+=i;
sum[i]=s;
}
}
int main()
{ int a,b;
set();
while(scanf(%d%d,a,b)!=EOF)
{
printf(%d\n,sum[b]-sum[a-1]);
}
}
2 求整数中1的个数
Count the number of “1” in an integer.
题目描述:求一个非负整数n,转换为R进制数后,数符1的个数
For a non-negative number n, after converting to R number system(R进制),Count the number of “1”。
输入:若干组测试数据,每组两个整数n和R,n为十进制数,R表示转换为R进制数,0=n=4600000000,2=R=4600000000
There are some groups of test data, each group has two integer n and R, R represents converting n to R number system,0=n=4600000000,2=R=4600000000
输出:输出数据为一个整数,即为答案
The output is an integer, which is the answer.
样例输入:
0 2
5 2
5 3
17 16
5 60
1 8
样例输出:
0
2
1
2
0
1
答案:
#includestdio.h
//除r取余法,不懂的问计算机基础老师,就是教你word、excel的那个
int f(int n,int r)
{
int count=0;
while(n)
{
if(n%r==1)count++;
n/=r;
}
return count;
}
int main()
{
int n,r;
while(scanf(%d%d,n,r)!=EOF)
printf(%d\n,f(n,r));
}
3 计算a和b
Calculate a and b
题目描述:已知两个非负整数a、b的和x,和它们的最小公倍数y,求这两个数
Given the sum of two non-negative numbers a and b is x, the lease common multiple (最小公倍数)of a and b is y, figure out a and b.
输入:有多组测试数据,每组一行,一行有两个整数x和y
There are some groups of test data, each group is in one line, there are two integer x and y.
输出:输出数据每行两个整数a和b,a=b
Output data, the requirement is that there are two in
您可能关注的文档
最近下载
- 人工智能在药物研发中的应用.pptx VIP
- 七氟丙烷灭火系统.pptx VIP
- 高盛-比亚迪-002594-聚焦中国高韧性企业:全球汽车市场上的新兴领先企业.docx
- 第2课 传感之古今未来课件+2025-2026学年人教版(2024)初中信息科技八年级全一册.pptx VIP
- 23S519小型排水构筑物(OCR).pdf VIP
- 第6课我们神圣的国土第2课时好山好水好风光 教学设计-2024-2025学年道德与法治五年级上册统编版.docx VIP
- CHINSC深川S160A变频器参数设置调试故障代码资料V1.2-2023.pdf
- 一种测定谷氨酰胺合成酶酶活的方法.pdf VIP
- 城市垃圾处理手册.pdf VIP
- 学习中心 高级工 线桥偏心.pptx VIP
原创力文档


文档评论(0)