All members of Hulafly love playing the famous network game called 'Lou 1 Zhuang' so much that Super Da Lord got mad with them. So he thought over and over and finally came up with a good idea to stop them. He consulted an ACM master and asked for the hardest problem ever in the world. Hulafly must solve this problem in order to get permission of playing 'Lou 1 Zhuang'. They, however, are so eager to play 'Lou 1 zhuang' and have no interest in this problem at all, so they turn to you for help. You can do this only if you swear that you will never tell Da Lord that you have helped them.

'Lou 1 Zhuang' is a game with only one but a very tall buiding in it and everybody runs a shop in this buiding ---- either a cake shop or a barbershop, each one occupies a whole floor. (Log in at www.xiaonei.com and check details at http://apps.xiaonei.com/soletower/tower.php?origin=2807) Super Da Lord asks that if the buiding is N stories high, how can we devided the floors(or the shops) and multiply the number of floors(or shops) in each part to make the product P as large as possible. Neverthless, Super Da Lord thought that it's still too hard for them, so he gave them some hints, he said:"Go and find the solutoin in 'Lou 1 Zhuang'!"

Given the buidings' height N, you are to find the largest P.

题意:给出一个数N,将它拆成若干个数的和,并将这些数相乘,问乘积最大是多少,答案mod2009

尽量拆成最多的3,进行相乘,结果最大,但是注意,若拆出若干个3,余数是1,则将1加到一个3中,作为4求乘积。

 #include<stdio.h>
#define mod 2009
int QuickPow(int a,long long n){
int temp=a,ans=;
while(n){
if(n&)ans=temp*ans%mod;
temp=temp*temp%mod;
n>>=;
}
return ans;
} int main(){
long long n;
while(scanf("%I64d",&n)!=EOF){
if(n==)printf("1\n");
else if(n==)printf("2\n");
else {
int ans=;
long long p=n/;
if (n%==){
ans=*QuickPow(,p-)%mod;
}
else if(n%==){
ans=*QuickPow(,p)%mod;
}
else if(n%==){
ans=*QuickPow(,p)%mod;
}
printf("%d\n",ans);
}
}
return ;
}

hdu2886 Lou 1 Zhuang 数学/快速幂的更多相关文章

  1. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  2. BZOJ-2326 数学作业 矩阵乘法快速幂+快速乘

    2326: [HNOI2011]数学作业 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1564 Solved: 910 [Submit][Statu ...

  3. Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏

    C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...

  4. BZOJ 2326: [HNOI2011]数学作业( 矩阵快速幂 )

    BZOJ先剧透了是矩阵乘法...这道题显然可以f(x) = f(x-1)*10t+x ,其中t表示x有多少位. 这个递推式可以变成这样的矩阵...(不会用公式编辑器...), 我们把位数相同的一起处理 ...

  5. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  6. 【做题】SRM701 Div1 Hard - FibonacciStringSum——数学和式&矩阵快速幂

    原文链接 https://www.cnblogs.com/cly-none/p/SRM701Div1C.html 题意:定义"Fibonacci string"为没有连续1的01串 ...

  7. 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂

    洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ...

  8. P3216 [HNOI2011]数学作业 (矩阵快速幂)

    P3216 [HNOI2011]数学作业 题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 NN 和 MM ,要求计算 Concatenate (1 .. N ...

  9. [HNOI2011]数学作业 矩阵快速幂 BZOJ 2326

    题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 NNN 和 MMM ,要求计算Concatenate(1..N) Concatenate (1 .. N) ...

随机推荐

  1. shell shell基本概述

    SHELL的概念 SHELL是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序, 用户可以用shell来启动,挂起,停止甚至是编写一些程序. ​ Shell还是 ...

  2. 外部点击链接,登陆后,直接跳转到该链接(过滤器 + Cookie实现)

    一.web.xml (1)指定过滤的Servlet类 (2)配置过滤规则,过滤以.mail结尾的链接 <?xml version="1.0" encoding="U ...

  3. 戴尔poweredge r730服务器配置以及系统安装

    第一次给服务器安装的是ubantu系统: 首先我们开机进入小型BIOS设置一下RAID,或者进入服务器管理系统,在系统的BIOS中进行RAID设置: 开机后当看到出现< Ctrl > &l ...

  4. Docker小白从零入门到实战系列【二】

    1.安装好Centos 7 2.关闭SELINUX sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/configsetenfo ...

  5. table-cell 布局

    table-cell能实现段落文字相对于div的垂直居中: 将div设置为display:table-cell; *display:inline-block;text-align:center; ve ...

  6. Zabbix4.0添加端口和进程监控

    一:Zabbix设置主动模式: vim /etc/zabbix/zabbix_agent.conf Server=192.168.1.10 #被动模式的serverip地址,如果设置纯被动模式,可以注 ...

  7. Centos7部署kubernetes Proxy(七)

    1.配置kube-proxy使用LVS(三个节点都装上去) [root@linux-node1 ssl]# yum install -y ipvsadm ipset conntrack [root@l ...

  8. 强化学习9-Deep Q Learning

    之前讲到Sarsa和Q Learning都不太适合解决大规模问题,为什么呢? 因为传统的强化学习都有一张Q表,这张Q表记录了每个状态下,每个动作的q值,但是现实问题往往极其复杂,其状态非常多,甚至是连 ...

  9. L256 翻译

    Should work be placed among the causes of happiness or be regarded as a burden? Much work isexceedin ...

  10. python3自学第二天,模块,三元运算

    1.模块的认识. sys模块,os模块等 如何引入模块 import os cmd_res1=os.system("dir") # 执行命令dir,不保存结果 print(cmd_ ...