题意:把n分成若干个数相加有几种分法。
1、把n分成若干个数:类似排列组合问题,把n个数分成若干个数,在n个数中间插板,有n-1个空位,一共2^(n-1)种分法
2、降幂:题目中最后mod(10^9+7),10^9+7是素数。与费马小定理相联系
前提:m是质数
化简:
费马小引理:
所以:
3、还需要用到快速模幂
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef unsigned long long LL;
const int modd=1e9+7;
// 快速模幂计算函数
LL powermod(LL a, LL n, LL m)
{
LL res = 1;
while(n) {
if(n & 1) { // n % 2 == 1
res *= a;
res %= m;
}
a *= a;
a %= m;
n >>= 1;
}
return res;
}
int main(){
char s[100005];
while(gets(s)){
int len=strlen(s);
LL result=0;
for(int i=0;i<len;i++){
result=(result*10+s[i]-'0')%(modd-1); //在将字符串转化为整数的过程中一直取模
}
result=(result-1)%(modd-1); //2^n-1
printf("%lld\n",powermod(2,result,modd));
}
return 0;
}