SPOJ - LOCKER 数论 贪心
题意:求出\(n\)拆分成若干个数使其连乘最大的值
本题是之江学院网络赛的原题,计算规模大一点,看到EMAXX推荐就做了
忘了大一那会是怎么用均值不等式推出结果的(还给老师系列)
结论倒还记得:贪心分解3,不够就用2凑
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e6+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll fpw(ll a,ll n,ll mod){
ll ans=1;
while(n){
if(n&1) ans=(ans*a)%mod;
n>>=1;
a=(a*a)%mod;
}
return ans;
}
int main(){
int T=read();
const int mod = 1e9+7;
while(T--){
ll n=read();
ll ans=0;
if(n%3==0){
ans=fpw(3,n/3,mod);
}else if(n%3==1){
if(n==1)ans=1;
else ans=fpw(3,n/3-1,mod)*4;//3 1 -> 2 2
}else{
if(n==2)ans=2;
else ans=fpw(3,n/3,mod)*2;//3 2
}
println((ans%mod));
}
return 0;
}
SPOJ - LOCKER 数论 贪心的更多相关文章
- Tsinsen A1504. Book(王迪) 数论,贪心
题目:http://www.tsinsen.com/A1504 A1504. Book(王迪) 时间限制:1.0s 内存限制:256.0MB Special Judge 总提交次数:359 ...
- SPOJ - LOCKER
SPOJ - LOCKERhttps://vjudge.net/problem/45908/origin暴力枚举2-102 23 34 2 25 2 36 3 37 2 2 38 2 3 39 3 3 ...
- 2018.10.31 NOIP模拟 一串数字(数论+贪心)
传送门 把每一个数aaa质因数分解. 假设a=p1a1∗p2a2∗...∗pkaka=p_1^{a_1}*p_2^{a_2}*...*p_k^{a_k}a=p1a1∗p2a2∗...∗pkak ...
- 2018.10.27 codeforces402D. Upgrading Array(数论+贪心)
传送门 唉我觉得这题数据范围1e5都能做啊... 居然只出了2000 考完听zxyzxyzxy说我的贪心可以卡但过了? 可能今天本来是0+10+00+10+00+10+0只是运气好T1T1T1骗了10 ...
- SPOJ ARCTAN (数论) Use of Function Arctan
详细的题解见这里. 图片转自上面的博客 假设我们已经推导出来x在处取得最小值,并且注意到这个点是位于两个整点之间的,所以从这两个整数往左右两边枚举b就能找到b+c的最小值. 其实只用往一边枚举就够了, ...
- SPOJ GCDEX (数论)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:求sigma (gcd (i , j)) ...
- Codefoces 432C Prime Swaps(数论+贪心)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26094917 题目连接:Codefoces ...
- CodeForces 124C Prime Permutation (数论+贪心)
题意:给定一个字符串,问你能不能通过重排,使得任意一个素数p <= 字符串长度n,并且 任意的 i <= 长度n/素数p,满足s[p] == s[p*i]. 析:很容易能够看出来,只要是某 ...
- codeforces 402 D. Upgrading Array(数论+贪心)
题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a ...
随机推荐
- 2-配置Andriod环境时的错误。。。Theme.AppCompat.Light
编译或运行时可能会出现错误: Error:Error retrieving parent for item: No resource found that matches the given name ...
- 使用pycharm运行调试scrapy
摘要 Scrapy是爬虫抓取框架,Pycharm是强大的python的IDE,为了方便使用需要在PyCharm对scrapy程序进行调试 python PyCharm Scrapy scrapy指令其 ...
- Flask框架 之 学生管理分析
先看模板吧. index.html <body> <h1>学生列表</h1> <table border="1"> <thea ...
- UCOSII在STM32F407上的移植
1.ucosii移植准备工作 1.1准备基础工程: 移植的时候需要一个基础工程,为了方便起见我们就选取跑马灯实验,作为ucossii移植的基础工程. 1.2Ucossii源码: 1)Micrium官网 ...
- Edge 自动给数字加下划线的问题
<meta name="format-detection" content="telephone=no,email=no,address=no">
- 在IE11(Win10)中检查up6.2配置
1.按F12,打开调试模式 2.打开调试程序选项卡 说明:在调试程序选项卡中可看到IE加载的脚本信息是否正确.因为IE有缓存,导致脚本有时不是最新的. 3.打开脚本,up6.js ...
- easyUI form sumit 中文乱码
jsp 编码方式: pageEncoding="UTF-8" tomcat 编码方式: <Connector connectionTimeout="20000&qu ...
- (转)基于 WPF + Modern UI 的 公司OA小助手 开发总结
原文地址:http://www.cnblogs.com/rainlam163/p/3365181.html 前言: 距离上一篇博客,整整一个月的时间了.人不能懒下来,必须有个阶段性的总结,算是对我这个 ...
- asp.net 设置分页
private const int PAGESIZE = 5; //定义每页有五行数据 private void FillPageList() { int pageCount = 0; // page ...
- .Net Core 项目区域请求设置
.net core 和asp.net MVC区域请求有个区别,这里重点记录一下 asp.net MVC 区域请求直接是/区域名称/控制名称/方法名称,其他不需要设置任何东西,而Core 项目这样请求路 ...