博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu2886 Lou 1 Zhuang 数学/快速幂
阅读量:6852 次
发布时间:2019-06-26

本文共 2261 字,大约阅读时间需要 7 分钟。

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求乘积。

 

1 #include
2 #define mod 2009 3 int QuickPow(int a,long long n){ 4 int temp=a,ans=1; 5 while(n){ 6 if(n&1)ans=temp*ans%mod; 7 temp=temp*temp%mod; 8 n>>=1; 9 }10 return ans;11 }12 13 int main(){14 long long n;15 while(scanf("%I64d",&n)!=EOF){16 if(n==1)printf("1\n");17 else if(n==2)printf("2\n");18 else {19 int ans=1;20 long long p=n/3;21 if (n%3==1){22 ans=4*QuickPow(3,p-1)%mod;23 }24 else if(n%3==2){25 ans=2*QuickPow(3,p)%mod;26 }27 else if(n%3==0){28 ans=1*QuickPow(3,p)%mod;29 }30 printf("%d\n",ans);31 }32 }33 return 0;34 }
View Code

 

转载于:https://www.cnblogs.com/cenariusxz/p/6592536.html

你可能感兴趣的文章
Go中链路层套接字的实践
查看>>
linux驱动的异步通知(kill_fasync,fasync)---- 驱动程序向应用程序发送信号
查看>>
安装Pycharm
查看>>
Laravel 4 Blade模板引擎
查看>>
数据持久化存储回顾
查看>>
《Spring_Four》第三次作业——基于Jsoup的大学生考试信息展示系统的原型设计与开发...
查看>>
团队开发——第一次冲刺第8天
查看>>
exFAT格式
查看>>
HDU 5379 Mahjong tree(dfs)
查看>>
requirejs主流程解读
查看>>
Handling PnP Paging Request
查看>>
5年后你想过什么样的生活?
查看>>
2019年春季学期第四周作业
查看>>
异步编程的数据同步
查看>>
RMAN常用备份恢复命令汇总
查看>>
openfire
查看>>
数组与排序
查看>>
Leetcode 编程训练
查看>>
Javascript IP檢測(弱正則)
查看>>
ajax提交数据
查看>>