算法提升之数学(唯一分解定理)
今天给大家介绍的是唯一分解定理,根据唯一分解定义可以求解某个数的因数个数,也可以求解因数之和。
一.唯一分解定理
二.约数个数定理
三.约数和定理
问题描述
给定你一个正整数 n,你需要求出 n! 的约数之和,结果对998244353 取模。
n!n 的阶乘,含义为 11×2×3×...×n。
输入格式
输入包含一个正整数 n。
输出格式
输出 n! 的约数之和,对 998244353 取模。
输入案例:
20
输出案例:
843703748
代码部分:
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
using ll=long long;
long long pp=998244353;
map<int,ll>mp;
void f(int n){for(int i=2;i<=n/i;i++){int cnt=0;if(n%i)continue;while(n%i==0){cnt++;n=n/i;}if(cnt)mp[i]+=cnt;}if(n>1)mp[n]++;
}
int main()
{ int a;cin>>a;for(int i=2;i<=a;i++)f(i);ll sum=1;for(auto &[p,c]:mp){ll res=0;ll t=1;for(int i=0;i<=c;i++){res=(res+t)%pp;t=t*p%pp; }sum=sum*res%pp;}cout<<sum<<'\n';return 0;
}
这是唯一分解的模版题,希望能对大家有所帮助,希望大家好好理解。