POJ 3604 Professor Ben
来源:互联网 发布:淘宝网休闲女鞋红 编辑:程序博客网 时间:2024/05/15 11:15
Description
Professor Ben is an old stubborn man teaching mathematics in a university. He likes to puzzle his students with perplexing (sometimes boring) problems. Today his task is: for a given integer N, a1,a2, ... ,anare the factors of N, let bi be the number of factors of ai, your job is to find the sum of cubes of all bi. Looking at the confused faces of his students, Prof. Ben explains it with a satisfied smile:
Let's assume N = 4. Then it has three factors 1, 2, and 4. Their numbers of factors are 1, 2 and 3 respectively. So the sum is 1 plus 8 plus 27 which equals 36. So 36 is the answer for N = 4.
Given an integer N, your task is to find the answer.
Input
The first line contains the number the test cases, Q(1 ≤ Q ≤ 500000). Each test case contains an integer N(1 ≤ N ≤ 5000000)
Output
For each test case output the answer in a separate line.
Sample Input
14
Sample Output
36
Source
题意:给一个数,求这个数的因数的因数个数的立方和,比如6的因子有1 2 3 6,1的因子数为1,2的为2,3的为2,6的为4,所以答案就是1^3+2^3+3^3+4^3=81
我是通过找规律找到答案的,如f(6)=f(2)*f(3)=81,而f(2)=f(3)=9,即当m,互质时f(m*n)=f(m)*f(n),当m可化为n^p时,f(m)=f(n^p)=(1^3+2^3+3^3+……+p^3),如f(4)=f(2^2)=1^3+2^3+3^3,f(18)=f(3^2*2)=f(3^2)*f(2)=36*9,当n为质数时,f(n)=9,结论就很明显了,就是一个唯一分解
详细推导过程可参考:http://blog.csdn.net/famousdt/article/details/7285382
#pragma comment(linker,"/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;const int Max=3e3;int m,n,p[Max/5];ll a[200],ans;bool vis[Max+1];void init()//打立方表,2^23>5e6,{ a[1]=1; for(int i=2;i<=23;i++) a[i]=a[i-1]+(ll)i*i*i;}void prime()//打素数表到3e3{ mem(vis,0); p[0]=0; vis[1]=1; for(int i=2;i<=Max;i++) { if(!vis[i])p[++p[0]]=i; for(int j=1;j<=p[0]&&(ll)i*p[j]<=Max;j++) { vis[i*p[j]]=1; if(!(i%p[j]))break; } }}void solve()//唯一分解{ for(int i=1;i<=p[0]&&(ll)p[i]*p[i]<=n;i++) { int num=0; while(!(n%p[i])) num++,n/=p[i]; if(num>1) ans*=a[num+1]; else if(num) ans*=9; } if(n>1)ans*=9;}int main(){ init(); prime(); sf("%d",&m); while(m--) { ans=1; sf("%d",&n); solve(); pf("%lld\n",ans); } return 0;}
- POJ 3604 Professor Ben
- POJ 3604 Professor Ben
- POJ 3604 Professor Ben
- POJ 3604 Professor Ben 数论
- poj 3604 Professor Ben 因子
- poj 3604 Professor Ben(质因数分解)
- poj 3604 Professor Ben 组合计数
- Professor Ben POJ
- POJ 3604 Professor Ben(合数唯一分解,筛法素数表)
- pku 3604 Professor Ben 积性函数加筛法
- POJ3604 Professor Ben[线性筛/暴力]
- Professor Ben 唯一分解定理:因子的因子个数
- Professor Emeritus
- Professor John
- dfs有向关系链,dfs所有有向边(poj Professor John)
- 修改Ben的PopupBox
- 项目总结(by BEN)
- Friends--S01E23--Ben出生
- 关于ScrollView拖拽事件和Button点击事件冲突解决方法
- 1~n 之间 数字x出现的次数
- 精品旅游项目第1天-项目搭建
- 英语学习--八月转折
- hdu6105(想法题)
- POJ 3604 Professor Ben
- 字符串多个范围替换
- 东北大学软件学院操作系统v实验报告
- 8月份英语总结
- 解决html转义及防止javascript注入攻击
- 字符串和算术式拼接的坑
- 周中训练笔记
- 2017 百度
- oracle分析函数