题意:求出\(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;
}

最新文章

  1. 烂泥:学习mysql的binlog配置
  2. 使用curl获取Location:重定向后url
  3. 学习记录012-NFS
  4. HTTP Post请求过程详解
  5. 如何获取数据块结构信息dump
  6. 第一章 02 谈谈static关键词
  7. Spring与Jdbc Demo
  8. js打开新窗口的两种方式
  9. Advanced Replication同步复制实验(基于Trigger&amp;基于Materialized View)
  10. #ifndef#define#endif的用法(整理)
  11. linux下GPRS模块使用AT命令实现拨接电话,发中英文短信
  12. python异常提示表
  13. delphi新手到高手的工具--castalia
  14. ios开发-引导页实现
  15. bootstrapValidator remote 的接受 验证 值
  16. Codeforces Round #364 (Div. 1) (差一个后缀自动机)
  17. mysql中,如何查看数据库中当前可用的校勘?字符集默认的collation?
  18. 031:Cetus sharding
  19. Java Collection 简介
  20. C# Winform Label内容根据其宽度自动调整字体大小

热门文章

  1. 4.std::string中库函数的使用。
  2. c++ 指向类成员函数的函数指针
  3. 第一次C语言作业:博客随笔
  4. 在IE11(Win10)中检查up6.2配置
  5. (一)ASP.NET中JavaScript的中英文(多语言)实现方案
  6. C# int?
  7. 【转】android手势处理揭秘
  8. string Format转义大括号
  9. laravel中chunk方法使用外部变量以及改变该变量
  10. .Net Core 项目区域请求设置