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 ...
随机推荐
- php中 为什么验证码 必须要开启 ob_clean 才可以显示
用ob_clean(),将前面的输出都清除就OK了 这表示你的程序前面有输出,<?php 前有空格.空行.文件有BOM头 ob_clean(); header("content-typ ...
- day23-python之日志 re模块
1.logging import logging #-----------------------------------logging.basicConfig logging.basicConfig ...
- python字符串处理方法
一.combine & duplicate 字符串结合和复制 字符和字符串可以用来相加来组合成一个字符串输出: 字符或字符串复制输出. 二.Extract &Slice 字符串提取和切 ...
- Codeforces Round #461 (Div. 2) B. Magic Forest
B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description ...
- CF 497 div 2 B
B. Turn the Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- laravel5.2总结--邮件
laravel自带SwiftMailer库,集成了多种邮件API,支持多种邮件驱动方式,包括smtp.Mailgun.Maildrill.Amazon SES.mail和sendmail,Mailgu ...
- Careercup - Microsoft面试题 - 5188169901277184
2014-05-12 06:12 题目链接 原题: Write a function to retrieve the number of a occurrences of a substring(ev ...
- Excel动画教程50例(一)
Excel动画教程50例(一) 1.自动筛选 2.在Excel中字符替换 3.在Excel中冻结行列标题 4.在Excel中为导入外部数据 5.在Excel中行列快速转换 6.共享Excel工作簿 7 ...
- github 客户端总是登录失败,提示密码错误
把输入法调成英文即可!!
- ios动画效果集锦(持续更新)
1.树叶滚动进度:http://www.jianshu.com/p/800496caa055 2.列表滚动动画和滚动视差效果http://www.jianshu.com/p/42e1eb59a1af ...