SPOJ:SUM OF PRODUCT(数论)
来源:互联网 发布:足球比赛分析软件 编辑:程序博客网 时间:2024/06/05 04:10
SUMPRO - SUM OF PRODUCT
Given a number N, find the sum of all products x*y such that N/x = y (Integer Division).
Since, the sum can be very large, please output this modulo 1000000007.
Input
The first line of input file contains an integer T, the number of test cases to follow. Each of the next T lines contain an integer N.
Output
Output T lines containing answer to corresponding test case.
Example
Input:
3246
Output:
41533
Constraints:
1 ≤ T ≤ 500
1 ≤ N ≤ 109
Sample Explanation:
Case #1:
2 / 1 = 2
2 / 2 = 1
Answer = 1 * 2 + 2 * 1 = 4
Case #2:
4 / 1 = 4
4 / 2 = 2
4 / 3 = 1
4 / 4 = 1
Answer = 1 * 4 + 2 * 2 + 3 * 1 + 4 * 1 = 15
思路:sqrt(n)以前的数老老实实地算,同时一边算一边将sqrt(n)后面的处理掉,就能O(sqrt(n))内解决,最后的sqrt(n)那里还要特判一下有没有算漏。
# include <bits/stdc++.h>using namespace std;typedef long long LL;const LL mod = 1e9+7;int main(){ LL t, n; scanf("%I64d",&t); while(t--) { scanf("%I64d",&n); LL i, l = n, r, ans=n; for(i=2; i<=sqrt(n); ++i) { r = n/i; ans = (ans+(l+r+1)*(l-r)*(i-1)/2+r*i)%mod; l = r; } LL rest = l-(--i); if(rest) ans = (ans + (i+i+rest+1)*rest*i/2)%mod; printf("%I64d\n",ans); } return 0;}
阅读全文
0 0
- SPOJ:SUM OF PRODUCT(数论)
- Sum of product
- URAL1014 - Product of Digits - 数论
- hdu4432 Sum of divisors(数论)
- POJ 1775 sum of Factorial (数论)
- POJ 1775 Sum of Factorials(数论)
- HDU4676 Sum Of Gcd (数论 + 分块)
- 【SPOJ】【P5971】【LCM Sum】【题解】【数论】
- SOJ-4310 Sum of product
- UVa 993 Product of digits(简单数论)
- SPOJ:Factorial Modulo(数论)
- hdu 5525 Product(数论)
- HDU 4676 Sum Of Gcd【数论,数据结构(分块)】
- Codeforces 396B On Sum of Fractions(数论)
- UVA 1210 Sum of Consecutive Prime Numbers(数论)
- CodeForces 616E Sum of Remainders(数论)
- POJ2739:Sum of Consecutive Prime Numbers(简单数论)
- CodeForces 396 B.On Sum of Fractions(数论)
- android集成微信三方遇到错误、空白、闪退等问题解决
- 程序员,你需要大量地阅读
- Android1
- CentOS7mini 安装MySQL5.6启动时报错:Starting MySQL. ERROR!
- Android2
- SPOJ:SUM OF PRODUCT(数论)
- Android 如何快速将json 生成 json实体Bean对象
- Android3
- vue事件处理器
- 常用svn命令
- css :box-sizing
- 微信小程序支付 后台处理逻辑 原创
- Android4
- Android5