The Boss on Mars

新手小白如何学习编程 学习目标推荐第一门语言优势网站 / APP 开发(前端)JavaScript浏览器原生支持,能快速做出可视化效果后端 / 服务器 / 数据分析Python语法简洁像英语,库多、应用广(入门友好)游戏开发先用电竞入门,再转专业引擎硬件 / 嵌入式(比如单片机)C 语言贴近硬件,行业标准办公自动化(Excel / 文档处理)Python快速解决重复工作(比如批量改文件)👉新手首选推荐。 阅读详情

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


思路: 求1~n内与n互素的四次方之和,可以先利用公式求1~n的四次方和:1^4+2^4+3^4+......+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30;然后在减去与n不互素的四次方之和(用容斥),这里要注意的是,因为n非常大,所以,直接除以30会导致答案错误,这时候就要用到逆元中的推论,设x为b/a模n的除数,若gcd(a,n)=1,则x=b/a (mod n)的解为x=b*a^(phi(n)-1);因为30^(phi(l)-1)%l=233333335,所以计算的时候可以把除以30转化为乘以233333335;计算的时候与x不互素的个数d=n/s;这时候又是一个1~d的四次方和公式;

代码如下:

#include<stdio.h>
#include<math.h>
long long p[10000],L=1000000007,m=233333335;
long long pp(int x)
{
    long long s=1;;
    for(int i=1;i<=4;i++)
        s=s*x%L;
        return s;
}
long long QH(long long n)
{
    return n*(n+1)%L*(2*n+1)%L*(3*(n*n)%L+3*n-1)%L*m%L;
}
int main()
{
    int t;
    long long n,w,x,S,cnt,y;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        scanf("%lld",&n);
        S=QH(n);
        cnt=0;
        x=n;
        for(int j=2;j*j<=x;j++)
        {
            if(x%j==0)
            {
                p[cnt++]=j;
                while(x%j==0)
                    x=x/j;
            }
        }
        if(x>1)
            p[cnt++]=x;
        for(int j=1;j<(1<<cnt);j++)
        {
            long long s=1,sum=0;
            for(int k=0;k<cnt;k++)
            {
                if(j&(1<<k))
                {
                    sum++;
                    s=s*p[k];
                }
            }
            s=pp(s)*QH(n/s)%L;
            if(sum%2)
                S=(S-s)%L;
            else
                S=(S+s)%L;

        }
        printf("%lld\n",(S+L)%L);
    }
    return 0;
}


用python画年度和月度的日历图 用python画各种日历图,可以区分月份来画也可以画一整年的,日历图中可以体现自己的信息 阅读详情

相关推荐

企业微信群机器人配置全攻略:从零到消息推送的完整流程

本文详细介绍了企业微信群机器人的配置与使用全流程,从零开始指导如何创建机器人、获取Webhook地址,到通过HTTP请求发送文本、Markdown、图片及模板卡片等多种消息类型。内容涵盖核心的接口配置、安全实践及实战应用场景,帮助开发与运维团队快速构建自动化消息推送中枢,提升协作效率。

weixin_29231725的博客 849

The Boss on Mars(容斥原理)

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 p

深海沧澜的博客 610

解决Calibre中license的错误

本次解决了Calibre在Cadence 617 virtuoso版本中运行不了的错误,在遇到问题的时候,我也跟你们一样,首先是上网查询为什么运行不了呢?明明我安装了之后里面有Calibre的,我当时也是这样的疑惑,一点Calibre运行LVS的时候,一片空白,然后就出现了license的错误,后来点点点,看看看,搜搜搜,最终解决了这个问题。虚拟机是VMware16版本,cadence617,Calibre是2015版本。旨在记录遇到的实际问题。

yytu231的博客 1万+

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

容斥原理 + 四次方求和 + 数论

代码改变世界 4022

别再手动抄表了!用MCGS触摸屏自动存数据到U盘,5分钟搞定报表导出

本文详细介绍了如何利用MCGS触摸屏实现工业数据自动记录与U盘导出,彻底告别传统手动抄表方式。通过昆仑通态MCGS系统,可构建零误差自动化报表系统,实现实时数据采集、双重备份及标准CSV格式导出,大幅提升数据准确性和工作效率。

weixin_30872157的博客 794

SAP成本控制范围配置全流程:从货币参数到标准层次(附2024最新SPRO路径)

本文详细拆解了SAP成本控制范围(Controlling Area)的完整配置流程,涵盖从货币与估价参数文件定义、参数文件分配到控制范围,再到成本中心标准层次创建等核心步骤。文章提供了2024年最新的SPRO导航路径和实战配置要点,帮助顾问构建稳健、可扩展的管理会计基础架构,并附有常见问题排查指南。

java5的博客 941

hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)

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

Alex 1172

模型瘦身术:YOLOv5无损剪枝实战教程

本文介绍了一种YOLOv5模型的无损剪枝方法,通过"稀疏训练+结构化剪枝+微调"的流程,在不损失精度的前提下显著减小模型尺寸并提升推理速度。具体步骤包括:1)稀疏训练给参数排优先级;2)裁剪不重要通道;3)微调恢复精度;4)验证效果。实战部分详细展示了从环境搭建到剪枝实现的完整流程,并分析了剪枝后在边缘设备部署、实时检测等场景的优势。该方法可使YOLOv5s模型从14MB缩减至2-3MB,推理速度提升30%-50%,适用于资源受限设备的轻量化部署需求。

LXY_LOVE36的博客 105

容斥原理---The Boss on Mars

D - The Boss on Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description On Mars, there is a huge company called ACM (A huge Compan

扬帆起航 683

【ACP】2025-最新-疑难题解析- 练习二汇总

全球加速是优化公网访问的,负载均衡是分发流量的,公网 NAT 网关是处理公网 IP 的,高速通道是建私网连接但不直接提供固定私网地址功能。C 是客户端加密方式,D 是 ECS 云盘加密,都不属于 OSS 服务器端加密。某企业想使用云服务器 ECS + 负载均衡 SLB + 弹性伸缩 (Auto Scaling) 的架构搭建一个企业级门户网站,技术负责人对于负载均衡和弹性伸缩配合使用没有经验,于是将他理解的两种产品配合使用的一些技术细节列成了一个表单,并请作为架构师的您帮他做一下鉴别,以下哪些项是正确的?

jundao1997的专栏 297

[深入研究4G/5G/6G专题-31]: 5G NR开机流程5.2 - UE Attach流程(Registeration Request/Accept/Complete)

目录前言:前置条件:第1章 5G NR UE attach流程(从UE log的视角看)1.0 NAS消息解析器1.1 消息交互流程1.2 UE Registeration Request消息(AMF->基站->UE)1.3 AMF Registeration Accept消息(AMF->基站->UE)1.4 UE Register complete消息(UE->基站->AMF)第2章 UE Register...............

文火冰糖(王文兵)的博客 7万+

HDU 4059 The Boss on Mars (容斥+快速幂+分解质因数)

HDU 4059 The Boss on Mars (容斥+快速幂+分解质因数)

Tc的专栏 1247

对称式目镜设计实例

对称式目镜设计实例

weixin_72050316的博客 1163

hdu4059 The Boss on Mars

The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1335    Accepted Submission(s): 401 Problem Description On Mars, t

习惯与规则决定命运 1516

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

HDU The Boss on Mars

http://acm.hdu.edu.cn/showproblem.php?pid=4059 本题便是对于利用容斥原理进行欧拉函数的求解的拓展....  n = p1^a1*p2^a2*p3^a3*...*pk^ak A1表示m的素因子分解中含有素因子p1, .... Ak表示m的素因子分解中含有pk,则与n互质的数A1至Ak性质均不满足,显然可以利用容斥原理来进行求解... phi(n

新的开始... 636

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu 4059 The Boss on Mars

The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1934    Accepted Submission(s): 580 Problem Description On Mars, t

浮躁的人,终究一事无成! 1373

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

3547 The Boss on Mars

#include #include #include using namespace std; typedef long long LL; const int MAXN = 10001; const LL M = 1000000007; int factor[10001]

nbu_james的专栏 805

hdu4059The Boss on Mars 容斥原理

//求1到n之间与n互质的数的四次方的和 //segma(n^4) = (6n^5+15n^4+10n^3-n)/30 //对于(a/b)%mod可以转化为(a*inv(b))%mod //inv(b)为b的逆元 //由费马小定理a^(p-1) = 1(modp) a , p 互质可得 //30的逆元为30^(mod-2) //由容斥原理很容易得到与n不互质的数之和为 //对于所有的

ijbuhv的专栏 1187

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 comment(linker,"/STACK:1024000000,1024000000") #include #include #define LL long long const LL mod

moyan_min的专栏 1252

hdoj 4059 The Boss on Mars

类型:数学 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4059 来源:2011 Asia Dalian Regional Contest 思路:参考:http://blog.sina.com.cn/s/blog_69c3f0410100vqfe.html 四次方和公式: f(n) = 1^4 + 2^4 + … + n^4 = n *

gold_bridge 384

HDU 4059 The Boss on Mars

做这个题目需要知道一个数学公式,1^4+2^4+3^4+...+n^4=1/5*n^5+1/2*n^4+1/3*n^3-1/30*n,然后容斥一下,就没有什么了。#include #include #include using namespace std; const int maxn=10010; const long long mod=1000000007; bool is_pri

岁月静好 813

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

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

Dacc123的博客 879

HDU 4059 The Boss on Mars 2011大连现场赛

转载请注明出处,谢谢 http://blog.youkuaiyun.com/ACM_cxlove?viewmode=contents           by---cxlove http://acm.hdu.edu.cn/showproblem.php?pid=4059 题目求1-n中与n互质的数的4次方之和,即S=a1^4+a2^4+……;  a1,a2……均小于等于n且与n互质。 先求出

窝不是爱酱,喵~~~~ 4143

HDU 4059 The Boss on Mars

http://acm.hdu.edu.cn/showproblem.php?pid=4059 题目 求区间 [ 1 , n ] 中所有与n互质的数的4次方和 题解 先筛素数 算出n的质因子 假设有一个质因子为x,令y=n/x,说明区间 [ 1 , n ] 中有y个数和x不互质,则 这y个数的和为 (1^4+2^4+3^4…..+y^4)* (x * x * x * x) 根据容斥...

RE:X 165
上一篇: Coprime
下一篇: Co-prime
绿蚁.r
博客等级 码龄10年 4粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值