Divisors of the Divisors of an Integer题解
Divisors of the Divisors of an Integer
题意:定义d[x]为x的因子个数,sndd[y]为y的因子的因子个数和。
思路:任意一个大于一的数,都可以分解为若干个质数的乘积。所以,这个问题可以转换成一个有关质数的问题。
如果x是一个质数,那么d[x^u] = u + 1。
分类加法,分步乘法。首先,每一步先选出来一个质数进行操作,对于每一个质数,需要将多种可能情况进行加和。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e7 + 7;
int n, t, prime[N], tot;
bool mark[N];
typedef pair<int,int> pii;
vector<pii> vet;
void get_prime(){
for(int i = 2; i <= 1e6; i++){
if(!mark[i]){
prime[++tot] = i;
mark[i] = 1;
}
for(int j = 1; j <= tot; j ++){
if(i * prime[j] > 1e6) break;
mark[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
}
}
}
//每个因数对答案的贡献是可以的算出来的
signed main(){
get_prime();
while(cin >> n){
//cin >> n;
if(n == 0) break;
vet.clear();
for(int i = 1; i <= tot; i ++){
//int x = n / prime[i];
int y = n, x = 0;
while(y){
x += y/prime[i];
y = y / prime[i];
}
if(x >= 1){
vet.push_back({prime[i], x});
}
}
int ans = 1;
for(int i = 0; i < vet.size(); i++){
int u = 0;
int x = vet[i].first, y = vet[i].second;
ans = ans * ((y + 1) + ((y + 1) * y / 2)%mod)% mod;
}
cout << ans << endl;
}
return 0;
}
本文作者:风归去
本文链接:https://www.cnblogs.com/N-lim/p/16663102.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步