题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1215

题目大意:

求N的因子和(不包括N本身)

解题思路:

模板传送门

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
#define Mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int INF = 1e9 + ;
const int maxn = +;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n)//返回n以内素数的个数
{
int p = ;
for(int i = ; i <= n; i++)is_prime[i] = ;
is_prime[] = is_prime[] = ;
for(ll i = ; i <= n; i++)
{
if(is_prime[i])
{
prime[p++] = i;
for(ll j = i * i; j <= n; j += i)is_prime[j] = ;//这里涉及i*i,必须使用long long
}
}
return p;
} ll Divisors_num(ll n, int tot)//素数总数
{
ll ans = ;
for(int i = ; i < tot && prime[i] * prime[i] <= n; i++)
{
if(n % prime[i] == )
{
int cnt = ;
while(n % prime[i] == )
{
cnt++;
n /= prime[i];
}
ans *= (cnt + );
}
}
if(n > )ans *= ;
return ans;
}
ll pow(ll a, ll b)
{
ll ans = ;
while(b)
{
if(b & )ans = ans * a;
a *= a;
b /= ;
}
return ans;
}
ll Divisors_sum(ll n, int tot)
{
ll ans = ;
for(int i = ; i < tot && prime[i] * prime[i] <= n; i++)
{
if(n % prime[i] == )
{
int cnt = ;
while(n % prime[i] == )
{
cnt++;
n /= prime[i];
}
ans = (pow(prime[i], cnt + ) - ) / (prime[i] - ) * ans;
}
}
if(n > )ans *= (n + );
return ans;
}
int main()
{
int T, cases = ;
int tot = sieve();
cin >> T;
while(T--)
{
ll n;
scanf("%lld", &n);
printf("%lld\n", Divisors_sum(n, tot) - n);
}
return ;
}

hdu1215 七夕节---因子和的更多相关文章

  1. hdu1215七夕节

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  2. HDU1215 七夕节(模拟 数学)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1215 七夕节 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  3. HDU-1215 七夕节 数论 唯一分解定理 求约数之和

    题目链接:https://cn.vjudge.net/problem/HDU-1215 题意 中文题,自己去看吧,懒得写:) 思路 \[ Ans=\prod \sum p_i^j \] 唯一分解定理 ...

  4. ITer的七夕节,你的情人在哪里(2015-08-19)

    自写<一个程序猿的生命周期>连载以来,迎来第一个七夕节,打算写篇文章纪念一下.我主张过中国自己的节日的,也不反对过其他国家的节日,但是要搞清楚其他国家节日的由来,不要把别人的鬼节当成我们的 ...

  5. HDOJ 1215 七夕节

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  6. hdu 1215 七夕节

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  7. 七夕节(hd1215)干嘛今天做这题T_T

    七夕节 Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!&q ...

  8. 【HDOJ 1215】七夕节

    七夕节 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissio ...

  9. 4C - 七夕节

    七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" 人们纷纷来到告示前,都想知道谁才是自己 ...

随机推荐

  1. centos7安装SourceCodePro字体

    1. 下载SourceCodePro字体,后缀应为.ttf. 2. 将字体文件复制到fonts(/usr/share/fonts)文件夹下: [root@centos fonts]# mv /home ...

  2. 螺旋队列(p98)

    先判断这个坐标代表的数位于哪一层,然后依据该层最大的数去计算这个坐标所代表的数. #include"iostream" #include"stdio.h" #i ...

  3. DbUtils(二) 结果集实例

    单行数据处理:ScalarHandler    ArrayHandler    MapHandler    BeanHandler 多行数据处理:BeanListHandler    Abstract ...

  4. java并发编程 - Exexctor简介

    Exexctor 常用类关系图 Executor 接口 Excutor 接口定义如下 ExecutorService ExecutorService 是一个比 Executor 使用更广泛的子类接口, ...

  5. LaTex 2

    LaTex 入门 此时是否安装成功 如果安装成功了LaTeX, 那么在计算机上会多出来LaTeX的编译器, LaTex Live 安装包在计算机上安装了多个不同的编译器, 有latex, xelate ...

  6. dojo入门

    1.引入dojo.js dojo的发行包里有4个子目录,要引入的文件是名叫"dojo"的子目录里的dojo.js. 假设你是这样的目录结构: project | +--dojo-l ...

  7. 深入理解JavaScript系列(12):变量对象(Variable Object)

    介绍 JavaScript编程的时候总避免不了声明函数和变量,以成功构建我们的系统,但是解释器是如何并且在什么地方去查找这些函数和变量呢?我们引用这些对象的时候究竟发生了什么? 原始发布:Dmitry ...

  8. 在 Azure 中创建静态 HTML Web 应用

    Azure Web 应用提供高度可缩放.自修补的 Web 托管服务. 本快速入门教程演示如何将基本 HTML+CSS 站点部署到 Azure Web 应用. 使用 Azure CLI 创建 Web 应 ...

  9. mysql的引擎和锁

  10. Javascript: hash tables in javascript

    /** * Copyright 2010 Tim Down. * * Licensed under the Apache License, Version 2.0 (the "License ...