[中等题] Project Euler 608 Divisor Sums

200人阅读 评论(0) 收藏 举报
分类:

这个题怎么Difficulty rating 80% 啊,送经验的感觉啊

D(m,n)=======d|mk=1nσ0(kd)d|mk=1na|kb|d[(a,b)=1]a=1nnad|mb|d[(a,b)=1]a=1nnad|mb|di|a,i|bμ(i)i|mμ(i)×(σ01)(mi)idnnidi|mμ(i)×(σ01)(mi)d=1ninidi|mμ(i)×(σ01)(mi)×f(ni)

这个 σ01 就是 111 ,就是把一个数分成三个有序的数的乘积的方案数。
满足条件且 μ(i)0i 不会太多,大概是 4.4×107 个,直接搜索。
f 这个东西全部预处理好,总计算量我算算了也就 109 级别,还是能接受的。

于是跑了 2.5min 答案就出来了

#include<cstdio>
#include<cstdlib>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const ll n=1e12,m=200;
const int P=1e9+7;

int p[205],num;
int vst[205];

int q[205];

inline void Pre(int n){
  for (int i=2;i<=n;i++){
    if (!vst[i]) p[++num]=i;
    for (int j=1;j<=num && i*p[j]<=n;j++){
      vst[i*p[j]]=1;
      if (i%p[j]==0)
    break;
    }
  }
}

inline ll C(ll x){
  return (x+2)*(x+1)/2;
}

ll Map1[1000005],Map2[1000005];

inline ll Calc(ll x){
  ll ret=0;
  for (ll i=1,j,t;i<=x;i=j+1){
    j=x/(t=x/i);
    ret+=t*(j-i+1);
  }
  return (x<=1e6?Map1[x]:Map2[n/x])=ret%P;
}
inline ll Map(ll x){
  return x<=1e6?Map1[x]:Map2[n/x];
}

ll ans=0;

inline void dfs(ll t,ll cur,ll mu,ll phi){
  static int Cnt=0;
  if (t==num+1){
    if ((++Cnt)%1000000==0)
      printf("%d\n",Cnt);
    if (mu==1)
      ans+=phi*Map(n/cur)%P;
    else
      ans+=P-phi*Map(n/cur)%P;
    return;
  }
  if (cur*p[t]<=n)
    dfs(t+1,cur*p[t],-mu,phi*C(q[t]-1)%P);
  dfs(t+1,cur,mu,phi*C(q[t])%P);
}

inline ll Brute(){
  ll mm=1;
  for (int i=1;i<=m;i++) mm*=i;
  int ret=0;
  for (int i=1;i<=mm;i++)
    if (mm%i==0)
      for (int j=1;j<=n;j++)
    for (int k=1;k<=i*j;k++)
      if ((i*j)%k==0)
        ret++;
  printf("%d\n",ret);
  return ret;
}
inline void GG(){
  //ll ret=0;
  ll Cnt=0;
  for (ll i=1,j;i<=n;i=j+1){
    j=n/(n/i);
    Calc(n/i);
    if ((++Cnt)%10000==0)
      printf("%lld %lld\n",i,Cnt);
  }
  //printf("%lld\n",ret);
  //return ret;
}

int main(){
  Pre(m);
  for (int i=1;i<=num;i++){
    q[i]=0;
    for (ll t=p[i];t<=m;t*=p[i])
      q[i]+=m/t;
  }
  GG();
  dfs(1,1,1,1);
  printf("%lld\n",ans%P);
  //Brute();
  return 0;
}
查看评论

各种语言版本实现欧拉猜想 Euler's sum of powers conjecture

Euler's sum of powers conjecture There is a conjecture in mathematics that held for over 200 ...
  • GarfieldEr007
  • GarfieldEr007
  • 2016-01-07 12:44:19
  • 649

Project Euler:Problem 23 Non-abundant sums

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number...
  • youb11
  • youb11
  • 2015-06-01 22:12:14
  • 672

【Project Euler】8 第八题

 A Pythagorean triplet is a set of three natural numbers, a a2 + b2 = c2 For example, 32 +...
  • NoMasp
  • NoMasp
  • 2015-02-07 12:26:00
  • 1398

Project Euler 1-5题

第1题 题目来源ProjectEuler这个题求的是严格小于1000的数中,是3或5的倍数的数的和。(刚开始理解错below的意思了,把1000算进去了,尴尬)int main(){ ...
  • pfccWang
  • pfccWang
  • 2017-09-10 21:25:29
  • 342

project Euler第八题

题目: Find the greatest product of five consecutive digits in the 1000-digit number. 7316717653133...
  • shangzhihaohao
  • shangzhihaohao
  • 2011-11-07 14:49:40
  • 600

Project Euler:Problem 8

The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 =...
  • youb11
  • youb11
  • 2015-05-30 12:16:18
  • 754

【Project Euler】3 第三题

 //The prime factors of 13195 are 5, 7, 13 and 29.         //What is the largest prime factor of...
  • NoMasp
  • NoMasp
  • 2015-02-07 12:21:52
  • 1171

ProjectEuler题解(更新到100题)

欧拉项目题解,源代码从Github上下载:https://github.com/cloudzfy/euler Multiples of 3 and 5Even Fib...
  • cloudzfy1
  • cloudzfy1
  • 2016-12-14 12:10:36
  • 704

project euler 解题

project euler 3:Any integer greater than 1 is either a prime number, or can be written as a unique p...
  • cctvzxxz1
  • cctvzxxz1
  • 2013-06-23 20:25:19
  • 3720

project euler problem 19 数周末

Counting Sundays Problem 19 You are given the following information, but you may prefer to...
  • u011466175
  • u011466175
  • 2013-10-07 15:02:21
  • 545
    个人资料
    持之以恒
    等级:
    访问量: 40万+
    积分: 1万+
    排名: 1233
    文章分类
    最新评论