zoukankan      html  css  js  c++  java
  • hdu4059 The Boss on Mars 容斥原理

    On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.

    Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.

    Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.

    容斥原理

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<math.h>
     5 using namespace std;
     6 typedef long long ll;
     7 
     8 const int mod=1e9+7;
     9 
    10 ll QP(ll a,ll n){
    11     ll ans=1,tmp=a;
    12     while(n){
    13         if(n&1)ans=ans*tmp%mod;
    14         tmp=tmp*tmp%mod;
    15         n>>=1;
    16     }
    17     return ans;
    18 }
    19 
    20 ll getsum(ll n){
    21     return n*(n+1)%mod*(2*n+1)%mod*((n*n*3%mod+n*3%mod-1+mod)%mod)%mod*QP(30,mod-2)%mod;
    22 }
    23 
    24 int pnum[50],num;
    25 
    26 int main(){
    27     int T;
    28     scanf("%d",&T);
    29     while(T--){
    30         int n;
    31         scanf("%d",&n);
    32         num=0;
    33         int tmp=n;
    34         for(int i=2;i*(ll)i<=tmp;++i){
    35             if(!(tmp%i)){
    36                 pnum[++num]=i;
    37                 while(!(tmp%i))tmp/=i;
    38             }
    39         }
    40         if(tmp-1)pnum[++num]=tmp;
    41         ll ans=0;
    42         for(int i=1;i<(1<<num);++i){
    43             int bit=0;
    44             int mul=1;
    45             for(int j=1;j<=num;++j){
    46                 if(i&(1<<(j-1))){
    47                     bit++;
    48                     mul*=pnum[j];
    49                 }
    50             }
    51             if(bit%2)ans=(ans+QP(mul,4)*getsum(n/mul)%mod)%mod;
    52             else ans=(ans-QP(mul,4)*getsum(n/mul)%mod)%mod;
    53         }
    54         printf("%lld
    ",((getsum(n)-ans)%mod+mod)%mod);
    55     }
    56     return 0;
    57 }
    View Code
  • 相关阅读:
    Django 支付宝付款接口的使用
    Django 处理跨域的配置、前台处理ajax
    pip安装源
    Django 缓存机制
    Django 配置使用日志
    Celery框架的基本使用方法
    python 虚拟环境的搭建
    Django 后台管理xadmin
    Python学习之路_day_16(模块搜索路径,开发规范)
    Python学习之路_day_15(模块)
  • 原文地址:https://www.cnblogs.com/cenariusxz/p/6597964.html
Copyright © 2011-2022 走看看