The Boss on Mars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2327    Accepted Submission(s):
718

Problem Description
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.

 
Input
The first line contains an integer T indicating the
number of test cases. (1 ≤ T ≤ 1000) Each test case, there is only one integer
n, indicating the number of employees in ACM. (1 ≤ n ≤ 10^8)
 
Output
For each test case, output an integer indicating the
money the boss can save. Because the answer is so large, please module the
answer with 1,000,000,007.
 
Sample Input
2
4
5
 
Sample Output
82
354

Hint

Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354

 
 
http://acm.hdu.edu.cn/showproblem.php?pid=4059
 
///这题主要是公式问题,然后稍微对容斥原理计算个数,改为mult的特殊利用即可;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
///1~n这n个数的4次方和:n*(n+1)*(6*n*n*n+9*n*n+n-1)/30; 这里百度的公式;
typedef long long ll;
const ll N = 1e6+5;
const ll mod = 1e9+7;
ll n, ans;
 
ll get4mult(ll mult)
{
    return mult*mult%mod*mult%mod*mult%mod;
}
ll extgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x = 1, y = 0; return a;
    }
    ll d = extgcd(b,a%b,x,y);
    ll t = x;
    x = y;
    y = t-a/b*y;
    return d;
}
ll inverse(ll t)
{
    ll x, y;
    ll d = extgcd(t,mod,x,y);
    return (x%mod+mod)%mod;
}
ll calu(ll n)
{
    return n*(n+1)%mod*(6*n*n%mod*n%mod+9*n*n%mod+n-1)%mod*inverse(30)%mod;
}
ll rongchi(ll n)
{
    ll m = n;
    vector<ll> v;
    for(ll i = 2; i*i <= m; i++){
        if(m%i==0){
            v.push_back(i);
            while(m%i==0) m/=i;
        }
    }
    if(m>1) v.push_back(m);
    ll len = v.size();
    for(ll i = 1; i < (1<<len); i++){
        ll mult = 1, ones = 0;
        for(ll j = 0; j < len; j++){
            if(i&(1<<j)){
                ones++;
                mult = mult*v[j];
            }
        }
        if(ones%2) {/// 变成了 -  因为假设是原来的容斥,那么cnt指的是不互质的个数,是要被剪掉的;
                ///而本题:也是要减掉,但是不是计算个数,而是对每一个过程有作用,减去:减变为了加,加变为了减;
            ans = ans-get4mult(mult)*calu(n/mult);
            ans = (ans%mod+mod)%mod;
        }else/// 变成了 +
        {
            ans = ans+get4mult(mult)*calu(n/mult);
            ans = (ans%mod+mod)%mod;
        }
    }
    v.clear();
    return ans;
}
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        ans = calu(n);
        printf("%lld\n",rongchi(n));
    }
    return 0;
}

The Boss on Mars的更多相关文章

  1. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  2. HDU 4059 The Boss on Mars 容斥原理

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu4059 The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4059 The Boss on Mars(容斥原理 + 四次方求和)

    传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. 数论 + 容斥 - HDU 4059 The Boss on Mars

    The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若 ...

  6. HDU 4059 The Boss on Mars(容斥原理)

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4059 The Boss on Mars

    The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 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 bo ...

  9. zoj 3547 The Boss on Mars

    需要用到概率论的容斥定理以及计算1 ^ 4 + 2 ^ 4 + ……+ n ^ 4的计算公式1^4+2^4+……+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30 #pragma comm ...

随机推荐

  1. 小白系列-免费广告路由器web认证设置(2)

    要设置认证页面图片.须要到后台注冊一个帐号,绑定路由器. 路由器管理后台网址 http://115.29.12.130/router 第一步:自己主动获取一个路由器ID(上一篇文章中的路由器ID也要改 ...

  2. [Android] SQLite数据库之增删改查基础操作

        在编程中常常会遇到数据库的操作,而Android系统内置了SQLite,它是一款轻型数据库,遵守事务ACID的关系型数据库管理系统,它占用的资源非常低,可以支持Windows/Linux/Un ...

  3. 算法笔记_078:蓝桥杯练习 最大最小公倍数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少. 输入格式 输入一个正整数N. 输出格式 输出一个整数,表示你 ...

  4. 05-spring-bean注入

    spring中只有两大核心技术: 控制反转(IOC)&依赖注入(DI),AOP(面向切面编程) 依赖注入:指利用配置文件的关系,来决定类之间的引用关系,以及数据的设置操作. 构造方法注入 默认 ...

  5. LoadRunner+Android模所器实现抓包并调试本地服务端

    步骤就是 1:新建LR脚本.协议选择Mobile Application - HTTP/HTML 2:在record里选择第三个:Record Emulator........ 3:  选择下一步后, ...

  6. Win7 + vs2012 + cocos2d-x2.2 配置开发环境

    昨天開始打算学习Cocos2d-x,首先肯定是要在自己的电脑上配置开发环境.昨天折腾了一天,以下将自己在当中遇到的问题与解决方法跟大家分享一下.大多数会遇到的问题,我都遇到了....     1.安装 ...

  7. RCC 2014 Warmup (Div. 2) A~C

    近期CF的pretext真是一场比一场弱.第一次在CF上被卡cin.cout.... A. Elimination time limit per test 1 second memory limit ...

  8. (四)Oracle学习笔记—— 常见函数

    1. 字符串类型及函数 字符类型分 种,char(n) .varchar(n).varchar2(n) : char(n)固定长度字符串,假如长度不足 n,右边空格补齐: varchar(n)可变长度 ...

  9. 给第三方dll加上强命名的方法[C#]

    在VS.NET 的命名行窗口下,输入如下的代码. 1 ,生成一个KeyFile sn -k keyPair.snk 2, 得到程序集的MSIL ildasm SomeAssembly.dll /out ...

  10. Python 多行注释

    Python 使用" # ” 进行单行注释,本身不带多行注释. 但在编译器 PyCharm 中,可以用以下方法注释多行代码: 1.“选中一段要注释的代码——>Ctrl+ / ” 即可注 ...