bzoj2226 LCMSum
来源:互联网 发布:位图转矢量图软件 编辑:程序博客网 时间:2024/06/03 16:33
Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. +
LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the
integers i and n. Input The first line contains T the number of test
cases. Each of the next T lines contain an integer n. Output Output T
lines, one for each test case, containing the required sum.
其中
而
在线性筛的时候顺便记下每个数最小质因子的幂,可以
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longconst int maxn=1000000;LL g[1000010];int prm[1000010],tot,pow[1000010];int rd(){ int x=0; char c=getchar(); while (c<'0'||c>'9') c=getchar(); while (c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); } return x;}void init(){ int i,j; g[1]=1; for (i=2;i<=maxn;i++) { if (!g[i]) { prm[++tot]=i; g[i]=(LL)i*(i-1)+1; pow[i]=i; } for (j=1;j<=tot&&(LL)i*prm[j]<=maxn;j++) if (i%prm[j]==0) { g[i*prm[j]]=g[i]+(LL)(prm[j]-1)*pow[i]*pow[i]*prm[j]*g[i/pow[i]]; pow[i*prm[j]]=pow[i]*prm[j]; break; } else { g[i*prm[j]]=g[i]*g[prm[j]]; pow[i*prm[j]]=prm[j]; } }}int main(){ int T,x; init(); T=rd(); while (T--) { x=rd(); printf("%lld\n",(g[x]+1)*x/2); }}
0 0
- bzoj2226 LCMSum
- 【bzoj2226】【spoj5971】【lcmsum】【数论】
- [bzoj2226][SPOJ5971]LCMSUM
- BZOJ2226: [Spoj 5971] LCMSum
- [bzoj2226] LCMSum 数学+筛法
- [BZOJ2226][Spoj5971][数论]LCMSum[好题]
- BZOJ2226
- spoj LCMSUM
- bzoj2226(数论)
- BZOJ2226 基础数论
- SPOJ LCMSUM (数论)
- SPOJ LCMSUM&GCDEX
- SPOJ LCMSUM (数论)
- [BZOJ 2226] LCMSum
- BZOJ 2226 Spoj 5971 LCMSum 数论
- BZOJ 2226 [Spoj 5971] LCMSum 数论
- bzoj2226(又是智商的突破,加油)
- [欧拉函数] BZOJ 2226 [Spoj 5971] LCMSum
- 忙碌的一天
- git常用命令
- 【CONCAT】使用之MySQL官方文档翻译
- 聚合数据(问答机器人)
- 深入react技术栈-源码问题1
- bzoj2226 LCMSum
- 数据类型
- spring_1-4,IOC&DI概述_配置 Bean_属性配置细节
- 洛谷 P1090 合并果子
- 【Adreno Profiler】Adreno Profiler & SnapDragon profiler 的安装和使用
- 代码审查中Handler会影响性能
- Ubuntu redis安装与使用
- POJ 1061 同余方程
- App内存分析工具——LeakCanary