题目描述 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. 输入 The first line contains T the number of test cases. Each of the next T lines contain an integer n. 输出 Ou…
题解: 考虑枚举gcd,然后问题转化为求<=n且与n互质的数的和. 这是有公式的f[i]=phi[i]*i/2 然后卡一卡时就可以过了. 代码: #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<…
2226: [Spoj 5971] LCMSum Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1123  Solved: 492[Submit][Status][Discuss] 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 in…
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 intege…
[BZOJ2226][Spoj 5971] LCMSum 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 n…
5152. Brute-force Algorithm EXTREME Problem code: BFALG Please click here to download a PDF version of the contest problems. The problem is problem B in the PDF. But the data limits is slightly modified: 1≤P≤1000000 in the original description, but i…
Katniss Everdeen after participating in Hunger Games now wants to participate in NT Games (Number Theory Games). As she begins President Snow provides her a number k. Then, she has to defend t back to back attacks from Haymitch Abernathy for practice…
1363 最小公倍数之和 题目来源: SPOJ 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 160 给出一个n,求1-n这n个数,同n的最小公倍数的和.例如:n = 6,1,2,3,4,5,6 同6的最小公倍数分别为6,6,6,12,30,6,加在一起 = 66. 由于结果很大,输出Mod 1000000007的结果. Input 第1行:一个数T,表示后面用作输入测试的数的数量.(1 <= T <= 50000) 第2 - T + 1行:T个数A[i](A[i] <…
题目: SPOJ-GCDEX (洛谷 Remote Judge) 分析: 求: \[\sum_{i=1}^{n}\sum_{j=i+1}^{n}gcd(i,j)\] 这道题给同届新生讲过,由于种种原因只讲了 \(O(n)\) 预处理欧拉函数 \(O(n)\) 查询的暴力做法,顺带提了一句 "这题能根号查询" 被教练嘴了 QAQ .以及小恐龙给我说有 \(O(n\log n)\) 预处理 \(O(1)\) 查询的另一种写法. 重点是前几天某学长讲课讲这道题,才知道有 \(O(n)\) 预…
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知识点:   欧拉函数.http://www.cnblogs.com/shentr/p/5317442.html 题解一: 当M==1时,显然答案为N. 当M!=1.  X是N的因子的倍数是 gcd(X,N)>1 && X<=N 的充要条件.so  先把N素因子分解, N=     …