MarioYC

Selectivo 2 - P7

Sep 2nd, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. #define MOD 1000000007
  7.  
  8. bool p[1000001];
  9. int f[1000001];
  10.  
  11. int main(){
  12.     memset(p,true,sizeof p);
  13.    
  14.     for(int i = 2;i <= 1000000;++i)
  15.         if(p[i] && i <= 1000)
  16.             for(int j = i * i;j <= 1000000;j += i)
  17.                 p[j] = false;
  18.    
  19.     f[0] = f[1] = 1;
  20.    
  21.     for(int i = 2;i <= 1000000;++i){
  22.         f[i] = f[i - 1] + f[i - 2];
  23.         if(f[i] >= MOD) f[i] -= MOD;
  24.     }
  25.    
  26.     int n;
  27.    
  28.     scanf("%d",&n);
  29.    
  30.     long long ans = 1;
  31.    
  32.     for(int i = 2;i <= n;++i){
  33.         if(p[i]){
  34.             int e = 0;
  35.            
  36.             for(int j = i;j <= n;j += i){
  37.                 int x = 0,aux = j;
  38.                
  39.                 while(aux % i == 0){
  40.                     aux /= i;
  41.                     ++x;
  42.                 }
  43.                
  44.                 e = (e + (long long)f[n - j] * x) % MOD;
  45.             }
  46.            
  47.             ans = ans * (e + 1) % MOD;
  48.         }
  49.     }
  50.    
  51.     printf("%lld\n",ans);
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment