N分成不同的数相乘使答案最大
题意:http://acm.hdu.edu.cn/showproblem.php?pid=5976
首先队友想出了分的越多答案越多。
我们就:2,3,4,5,6.。。多出来的尽量往小了加就行了。
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef vector<int> VI;
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; ll a[N],sum[N],up[N];
int er[]={,,,,,,,,,,,,,,,,};
ll qpow(ll a,ll b,ll mod)
{
ll ans;
// a%=mod;
ans=;
while(b!=)
{
if(b&)
ans=(ans*a)%mod;
b/=;
a=(a*a)%mod;
}
return ans;
} int main()
{
sum[]=;
up[]=;
a[]=;
for(int i=;i<=N-;++i)
a[i]=i+,sum[i]=i++sum[i-],up[i]=up[i-]*(i+)%mod;
ll x;
int T;
sc("%d",&T);
while(T--)
{
sc("%lld",&x);
if(x<=)
{
cout<<x<<endl;
continue;
}
int temp=;
for(int i=;i>=;--i)
{
if(sum[temp+er[i]]<=x)
temp+=er[i];
}
ll out=x%sum[temp];
if(temp+-out>=)
{
ll other=up[temp]*qpow(a[out?temp+-out:temp],mod-,mod)%mod;
ll ans=other*(a[out?temp+-out:temp]+out)%mod;
pr("%lld\n",ans);
}
else
{
ll other=up[temp]*qpow(,mod-,mod)%mod;
ll ans=other*(+out)%mod;
pr("%lld\n",ans);
}
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
N分成不同的数相乘使答案最大的更多相关文章
- Java 递归解决 "仅仅能两数相乘的计算器计算x^y" 问题
/** * 求一个数的乘方 * 求x^y,y是一个正整数. 设计算器仅仅能计算两数相乘,不能一次计算n个数相乘. * 知:2^5=(2^2)^2*2; 2^6=(2^2)^3=((4)^2)*4; 2 ...
- java两数相乘基础算法
下面是别人给我的代码: package com.bootdo; public class Test { public static void main(String[] args) { System. ...
- C语言100题集合005-删除一维数组中所有相同的数,使之只剩一个
系列文章<C语言经典100例>持续创作中,欢迎大家的关注和支持. 喜欢的同学记得点赞.转发.收藏哦- 后续C语言经典100例将会以pdf和代码的形式发放到公众号 欢迎关注:计算广告生态 即 ...
- 使用OC语言编写两个超大数相乘或相加的算法的思路和超大正整数相乘的代码
正文: 在编程中,无论是OC还是C亦或是C++语言,所声明的整数变量都会在内存中占有固定的存储空间,而这些存储空间都是固定的. 比如我们知道的int.long.short.unsigend int.u ...
- 【BZOJ1594】[Usaco2008 Jan]猜数游戏 二分答案+并查集
[BZOJ1594][Usaco2008 Jan]猜数游戏 Description 为了提高自己低得可怜的智商,奶牛们设计了一个新的猜数游戏,来锻炼她们的逻辑推理能力. 游戏开始前,一头指定的奶牛会在 ...
- openjudge 和为给定数(二分答案)
嗯... 题目链接:http://noi.openjudge.cn/ch0111/07/ 这道题是一道不太明显,但很好二分的二分答案的一道题... 首先排序(二分要满足单调性),然后枚举每一个数,在[ ...
- 从一个n位数中选出m位按顺序组成新数并使其最大 || Erasing and Winning UVA - 11491
就是从n位数中取出n-d个数字按顺序排成一排组成一个新数使得其最大 算法: 从前往后确定每一位.找第i位时,要求后面留下d-i位的空间, 因此第i位应该从第i-1位原来位置+1到第d+i位寻找 用线段 ...
- A<=B的前提下全排列A使答案尽量大
题意:http://codeforces.com/problemset/problem/915/C 举个例子:假使排好序后a字符串是123456,b是456456,按照上述方法遍历,213456 -& ...
- python 用加法实现a,b两数相乘
"""思路:1.a * b = a + a + a + ... 2.a * b = n个a相加,只需求证b = n即可 3.用for 循环遍历即可,b就是range的最大 ...
随机推荐
- 获取 Django版本号的两种方式
one k@ubuntu:~$ python Python ( , ::) [GCC ] on linux2 Type "help", "copyright", ...
- python+socket+jq实现web页面实时输出结果
例如有这样一个需求: 在终端上进行ping操作,现在想把这个这个操作放到web页面上进行,并且实现实时输出的效果. 来分析下具体实现过程 第一步,传统的http请求实现这个有点不太友好,因为这里边是一 ...
- mysql —日志记录
日志 事务日志: transaction log 中继日志: reley log错误日志: error log 通用日志: general log 慢查询日志: slow query log 二进制日 ...
- 慎用array_filter函数
array_filter (PHP 4 >= 4.0.6, PHP 5, PHP 7) array_filter - 用回调函数过滤数组中的单元 说明 array array_filter ( ...
- vue问题五:element ui组件的开始时间-结束时间验证
<el-date-picker v-model="seach.before" type="date" placeholder="开始时间&quo ...
- C之内存地址
计算机的内存地址 * 32位系统最多能识别4G内存 * 32位系统的地址总线长度是32位的,也就是说能分配给内存地址的数字是 2的32次方个 * 内存中每一个字节都需要一个内存地址 * 一个数字对用一 ...
- IEnumerable和IQueryable口的区别
IQueryable: 动态表达式树拼接查询语句,把拼接后查询语句进行执行:Execute触发,延迟加载IEnumerable:对内存中的数据,动态拼接查询语句,进行查询:ToList触发,延迟加载: ...
- 如何不让Excel图表随源数据改变而改变
如何不让Excel图表随源数据改变而改变 一般我们在用Excel时,经常会碰到一些问题,比如,如何才能不让Excel图表随源数据改变而改变呢,下面就谈一下,一般在默认情况下,Excel的图表在一个区域 ...
- Sql 中常用日期转换Convert(Datetime) convert datetime
Convert(data_type,expression[,style]) Convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...
- Python实现字符串反转
将字符串 s=‘helloword’ 反转输出为 ‘drowolleh’,以下通过多种方法实现 1.字符串切片法(常用) s='helloword' r=s[::-1] print(r) #结果:dr ...