链接:https://ac.nowcoder.com/acm/problem/50418
来源:牛客网
题目描述
\sum_{i=1}{n}{}\sum_{j=1}{i}{i*\left[ \frac{i}{j}\right]^{j}}∑
i=1
n
∑
j=1
i
i∗[
j
i
]
j
由于n越大jelly越美味,这里n<=3000000,只需求这个式子对1e9+7取模的值。
输入描述:
第一行输入一个整数 n。 1<=n<=3000000。
输出描述:
输出一个整数表示答案。
示例1
输入
复制
3
输出
复制
22
更换一下枚举顺序更加容易得到
我这里枚举的是j和那个结果然后求出i。
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_cxx;
#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
inline void print(INT x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int N = 3e6 + 10;
const int M = 3 * N;
const int mod = 1e9 + 7;
const int PP = 131;
const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);
int primes[N], cnt;
bool st[N];
void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] <= n / i; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
int qmi(int a, int b){
int res = 1;
while(b){
if (b & 1) res = res % mod * a % mod;
a = a % mod * a % mod;
b >>= 1;
}
return res % mod;
}
signed main(){
int ans = 0;
int n;
gt(n);
for (int i = 1; i <= n; i ++){
ans = ans % mod + i * (i - (i / 2)) % mod;
ans %= mod;
}
//get_primes(n);
for (int i = 1; i <= n; i ++){
for (int j = 2; j * i <= n; j ++){
int temp = i * j;
//while(temp / i == j && temp <= n) ans = ans % mod + temp * qmi(j, i) % mod, temp ++;
int temp2 = min((j + 1) * i - 1, n);
for (int k = temp; k <= temp2; k ++) ans = ans % mod + k * qmi(j, i) % mod;
}
}
ans %= mod;
print(ans);
return 0;
}