[Project Euler 429] Sum of squares of unitary divisors(数论)
Posted xxzh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Project Euler 429] Sum of squares of unitary divisors(数论)相关的知识,希望对你有一定的参考价值。
题目链接:https://projecteuler.net/problem=429
题目:
A unitary divisor dd of a number nn is a divisor of nn that has the property gcd(d,n/d)=1
The unitary divisors of 4!=24 1,3,8 and 24.
The sum of their squares is $1^2+3^2+8^2+24^2$=650.
Let S(n) represent the sum of the squares of the unitary divisors of nn. Thus S(4!)=650
Find S(100000000!) modulo 1000000009.
题解:
第二行的"所以 S(n2) "改成"所以 S(n!)"
代码如下:
#include<algorithm> #include<cstring> #include<cstdio> #include<iostream> using namespace std; typedef long long ll; const int N=1e8+15; const int mod=1e9+9; ll n,tot,ans; ll prime[N],vis[N]; void get_prime() { for (ll i=2;i<=n;i++) { if (!vis[i]) prime[++tot]=i; for (ll j=1;j<=tot&&prime[j]*i<=n;j++) { vis[prime[j]*i]=1; if (i%prime[j]==0) break; } } } ll mul(ll a,ll b) { ll res=0; for (;b;b>>=1,a=(a+a)%mod) if (b&1) res=(res+a)%mod; return res; } ll qpow(ll a,ll b) { ll res=1; for (;b;b>>=1,a=mul(a,a)%mod) if (b&1) res=res*a%mod; return res; } ll solve(ll a,ll b) { ll res=0; while (a) { a/=b; res+=a; } return res; } int main() { //scanf("%lld",&n); n=1e8; ans=1; get_prime(); for (ll i=2;i<=n;i++) { if (!vis[i]) { ll power=solve(n,i); ans=1ll*ans*(qpow(i,power*2)+1)%mod; } } printf("%lld",ans); return 0; }
本博客内容转自http://www.cnblogs.com/LzyRapx/p/8280943.html
以上是关于[Project Euler 429] Sum of squares of unitary divisors(数论)的主要内容,如果未能解决你的问题,请参考以下文章
Project Euler:Problem 88 Product-sum numbers
Project Euler——13.Larger Sum总结