hdu 2582(数论相关定理+素数筛选+整数分解)
f(n)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 457 Accepted Submission(s): 279
f(n)= Gcd(3)+Gcd(4)+…+Gcd(i)+…+Gcd(n).
Gcd(n)=gcd(C[n][1],C[n][2],……,C[n][n-1])
C[n][k] means the number of way to choose k things from n some things.
gcd(a,b) means the greatest common divisor of a and b.
The output consists of one line with one integer f(n).
26983
n为素数:本身
n有多个素因子:1
n只有一个素因子:该因子
920MS才跑过去。。没优化了。。记得用_int64保存结果。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL; const int N = ;
bool p[N];
LL g[N];
LL f[N];
void init(){
memset(g,,sizeof(g));
for(int i=;i<N;i++){
if(!p[i]){
g[i]=(LL)i;
for(LL j = (LL)i*i;j<N;j+=i){
p[j] = true;
}
}
}
f[]=;
for(int i=;i<N;i++){
int cnt = ;
if(g[i]==){
int temp=-;
int n = i;
for(int j=;j*j<=n;j++){
if(n%j==){
temp=(LL)j;
cnt++;
while(n%j==){
n/=j;
}
}
}
if(n>) {temp=(LL)n,cnt++;}
if(cnt!=) g[i]=;
if(cnt==) g[i]=(LL)temp;
}
f[i]=f[i-]+g[i];
}
}
int main()
{
init();
int n;
while(~scanf("%d",&n)){
printf("%lld\n",f[n]);
}
return ;
}
hdu 2582(数论相关定理+素数筛选+整数分解)的更多相关文章
- hdu 2685(数论相关定理+欧几里德定理+快速取模)
I won't tell you this is about number theory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- hdu 2136(质数筛选+整数分解)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- POJ2689 Prime Distance(数论:素数筛选模板)
题目链接:传送门 题目: Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Des ...
- HDU 2161 Primes (素数筛选法)
题意:输入一个数判断是不是素数,并规定2不是素数. 析:一看就很简单吧,用素数筛选法,注意的是结束条件是n<0,一开始被坑了... 不说了,直接上代码: #include <iostrea ...
- CPC23-4-K. 喵喵的神数 (数论 Lucas定理)
喵喵的神∙数 Time Limit: 1 Sec Memory Limit: 128 MB Description 喵喵对组合数比較感兴趣,而且对计算组合数很在行. 同一时候为了追求有后宫的素养的生活 ...
- HDU4548美素数——筛选法与空间换时间
对于数论的学习比较的碎片化,所以开了一篇随笔来记录一下学习中遇到的一些坑,主要通过题目来讲解 本题围绕:素数筛选法与空间换时间 HDU4548美素数 题目描述 小明对数的研究比较热爱,一谈到数,脑子里 ...
- acm数论之旅--数论四大定理
ACM数论之旅5---数论四大定理(你怕不怕(☆゚∀゚)老实告诉我) (本篇无证明,想要证明的去找度娘)o(*≧▽≦)ツ ----------数论四大定理--------- 数论四大定理: 1.威 ...
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
随机推荐
- Hive如何根据表中某个字段动态分区
使用hive储存数据时,需要对做分区,如果从kafka接收数据,将每天的数据保存一个分区(按天分区),保存分区时需要根据某个字段做动态分区,而不是傻傻的将数据写到某一个临时目录最后倒入到某一个分区,这 ...
- Olympic Class Ships【奥林匹克级邮轮】
Olympic Class Ships You probably know about the Titanic, but it was actually just noe of three state ...
- MAX(数论)
Description 小C有n个区间,其中第i个区间为[li,ri],小C想从每个区间中各选出一个整数,使得所有选出的数and起来得到的结果最大,请你求出这个值. Input Format 第一行一 ...
- 百度之星初赛A 今夕何夕
今夕何夕 今天是2017年8月6日,农历闰六月十五. 小度独自凭栏,望着一轮圆月,发出了"今夕何夕,见此良人"的寂寞感慨. 为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年 ...
- CentOS下的Redis启动脚本
这是一个Shell脚本,用于管理Redis进程(启动,停止,重启),如果你在使用Redis,这个脚本可供参考. #!/bin/sh # # redis - this script starts and ...
- 动态加载css,js
function dynamicLoadCss(url) { var head = document.getElementsByTagName('head')[0]; var link = docum ...
- 平衡树 - Luogu 1486 郁闷的出纳员
这么久没写平衡树了,再来一发... P1486 郁闷的出纳员 题目描述 OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的 ...
- mysql中为int设置长度究竟是什么意思
根据个人的实验并结合资料:1.长度跟可以使用的值的范围无关,值的范围仅跟类型对应的存储字节数和是否unsigned有关:2.长度指的是显示宽度,比如,指定3位int,那么id为3和id为300的值,在 ...
- C语言其他知识总结
1.常指针与指针常量 诀窍:观察const修饰的是谁,那谁就不可更改. const int *p;//const 修饰*p,所以*p不能更改.通过指针不可更改指向的值 int const *p;//同 ...
- CSU-2031 Barareh on Fire
CSU-2031 Barareh on Fire Description The Barareh village is on fire due to the attack of the virtual ...