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 ... 
随机推荐
- Docker学习笔记_安装和使用mysql
			一.系统环境和准备 1.宿主机OS:Win10 64位 2.虚拟机OS:Ubuntu18.04 3.操作账号:docker 二.安装 1.搜索mysql镜像:docker search mysql 2 ... 
- 数字图像处理实验(12):PROJECT 05-03,Periodic Noise Reduction Using a Notch Filter                                                                                                         标签:               图像处理MATLAB                                            2017-0
			实验要求: Objective: To understand the principle of the notch filter and its periodic noise reducing abi ... 
- 使用 append 方法追加元素
			来自于<sencha touch 权威指南> 学习使用 Ext.DomHelper 组件在页面中追加元素.app.js代码如下: Ext.require(['Ext.form.Panel' ... 
- python gridsearchcv 里的评价准则
			http://scikit-learn.org/stable/modules/model_evaluation.html 3.3.1. The scoring parameter: defining ... 
- Python开发 第一篇 python的前世今生
			Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ... 
- CSS 中的 px、em、rem 和 vh
			区分 px:Pixel.像素. em:相对长度单位.继承父级元素的 font-size,值是相对于父级元素font-size的倍数. rem:Root em.相对于根元素(即 <html> ... 
- Requests接口测试(二)
			requests安装先看下怎么安装requests, 执行以下命令: pip install requests 安装好后如何导入requests模块呢? 如下所示: import requests 基 ... 
- .net 空接合操作符 ??
			C# 提供了一个所谓的 ”空接合操作符“ - 即??操作符,他要获取两个操作数. 假如左边的操作数部位null,就返回这个操作数.如果左边的操作数为null就返回右边. 空接合操作符一个妙处在于,它既 ... 
- LSI SAS3IRCU配置SAS3系列RAID卡
			LSI SAS3IRCU配置SAS3系列RAID卡 一.适用的controller LSISAS3008 LSISAS3004 二.名词解释 Controller: IR: Volume: 卷,基于物 ... 
- 协程《二》greenlet模块
			一 greenlet模块 如果我们在单个线程内有20个任务,要想实现在多个任务之间切换,使用yield生成器的方式过于麻烦(需要先得到初始化一次的生成器,然后再调用send...非常麻烦),而使用gr ... 
