hdu 2886 Lou 1 Zhuang

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. 

Input

The buidings' height N. (1 <= N <= 10^9) 
 

Output

The product you've found P (mod 2009). 
 

Sample Input

1
2
3
4

Sample Output

1
2
3
4

        
  

Hint

Hint
You can apply to be huhupao, flytosky and koala's friends at xiaonei.com.

题意 将n分成若干个数的和,求这些数乘积的最大值

题解:将一个数分解成两个数的和当然是把这个数除以2

所以 结果会有很多2和3

然后2*2*2 又可以换为3*3 

所以最后求得是有多少个3,求余剩1的话 就把最后那个1换成4求解  其他不变

#include <bits/stdc++.h>
#define mod 2009
using namespace std;
typedef long long int ll;
int quick_powmod(ll a,ll b,int m)
{
    a%m;
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return int(ans);
}
int main()
{
    ll n;
    while(scanf("%lld",&n)!=EOF)
    {
        if(n==1)
            printf("1\n");
        else if(n==2)
            printf("2\n");
        else
        {
            int ans=1;
            long long p=n/3;
            if (n%3==1)
            {
                ans=4*quick_powmod(3,p-1,mod)%mod;
            }
            else if(n%3==2)
            {
                ans=2*quick_powmod(3,p,mod)%mod;
            }
            else if(n%3==0)
            {
                ans=1*quick_powmod(3,p,mod)%mod;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}

 

全部评论

相关推荐

个人背景:学院二本计科专业&nbsp;大二开始实习个人经历:安克创新&nbsp;、理想汽车、字节跳动碎碎念:我做事只有三分钟热度。看到进了大厂的同学,我会羡慕,也会跟着努力上进;但遇到好看的小说,我又会放下手头的事沉迷其中,之前的坚持也就中断了。我有些自卑,总觉得自己学历和外貌都不够好。之前偶然在网上受到关注,我就喜欢上了上网,因为这里有很多人认可我。但我也很在意别人的评价,偶尔看到嘲讽的言论,会触发我的自卑情绪,让我感到愤怒。有时候我会强硬地回怼,有时候又会懦弱地选择无视。我也有虚荣心。不管是拿到安克、理想还是字节的机会,我在分享的时候都会带着这份心思。我会特意强调自己学历不好,是为了衬托出过程的艰难,以此显得自己更厉害。我知道,人往往会炫耀自己缺少的东西,来掩盖内心的空洞。我总想着走捷径,不太喜欢踏踏实实地做事。找实习的时候,我花了更多时间在研究面试技巧上,而不是提升专业能力。我会反复听面试录音分析技巧,看面试教程学习怎么和不同的面试官沟通,还会每天自言自语练习语言表达,同学都觉得我有点奇怪。我的实习生涯里,侥幸和运气占了很大一部分。我总在想,如果有一天我失去了这份幸运,这些特质可能会让我一蹶不振。ps:&nbsp;很多人会问我学习路线和经验&nbsp;但是就像我上面说的&nbsp;我的实习过程靠的很多是关键节点的运气&nbsp;技术上面我可能不如很多人&nbsp;&nbsp;所以请大家理性求助和理性参考我的回答&nbsp;附上我的投递记录
我的offer在哪里...:从去年看到现在,飞升哥就是榜样
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务