[HDU 2824]The Euler function
2015-07-16 11:44
393 查看
The Euler function
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+….+ (b)Input
There are several test cases. Each line has two integers a, b (2Output
Output the result of (a)+ (a+1)+….+ (b)Sample Input
3 100Sample Output
3042Source
2009 Multi-University Training Contest 1 - Host by TJU题目大意
求a-b的phi[i]之和没看到several cases WA了N多次QAQQQQQQ
const maxn=10000000; var check:array[0..maxn]of boolean; phi,prime:array[0..maxn]of longint; n,i,j,a,b,len:longint; ans:int64; begin n:=3000000; len:=0; for i:=2 to n do begin if check[i]=false then begin inc(len); phi[i]:=i-1; prime[len]:=i; end; for j:=1 to len do begin if prime[j]*i>n then break; check[i*prime[j]]:=true; if i mod prime[j]=0 then begin phi[i*prime[j]]:=phi[i]*prime[j]; break; end else phi[i*prime[j]]:=phi[i]*(prime[j]-1); end; end; while not eof do begin readln(a,b); ans:=0; for i:=a to b do inc(ans,phi[i]); writeln(ans); end; end.
相关文章推荐
- sprintf函数的用法
- 一些大公司面试题整理
- iOS学习笔记-协议,代码块,分类
- jquery选择器
- acdream 小晴天老师系列——竖式乘法(简单穷举)
- Linux汇编与C互相调用
- Classloader工作机制
- VS常用快捷键一览表
- linux中shell变量$#,$@,$*,$?,$0,$1,$2的含义解释
- interllij IDEA scala报错
- 基本jquery
- DIV悬浮在页面底部或头部
- Square:从今天开始抛弃Fr 4000 agment吧!
- java 注解:SuppressWarnings、Deprecated、Override
- 中文分词解析
- linux shell if 参数
- hdu 1251 统计难题(字典树)
- 【ACM】-斐波那契数列 -- 递归并不一定就是好
- hadoop集群环境的搭建
- [leedcode 88] Merge Sorted Array