焦作赛区网络预赛-I Give Candies 欧拉降幂 ʕ •ᴥ•ʔ

本文探讨了一个有趣的数学问题:幼儿园老师如何随机分配糖果给孩子们,使得分配方式尽可能多样化。通过欧拉公式和幂运算,文章提供了一种计算不同分配结果数量的方法,并附带了C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.

Input

The first line contains an integer TT, the number of test case.

The next TT lines, each contains an integer N.

1 \le T \le 1001≤T≤100

1 \le N \le 10^{100000}1≤N≤10100000

Output

For each test case output the number of possible results (mod 1000000007).

样例输入复制

 
  1. 1

  2. 4

样例输出复制

8

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

欧拉公式 详细请看此博客 https://blog.youkuaiyun.com/henucm/article/details/82725457

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#define N 1e5+10
#define ll long long
using namespace std;
const int mod=1e9+7;
char s[100010];
ll ol(ll x)
{
	ll ans=x;
	for(ll i=2;i*i<=x;i++)
	{
		if(!x%i)
		{
			ans=ans/i*(i-1);
			while(x%i)
			{
				x=x/i;
			}
		}
	}
	if(x!=1)
	{
		ans=ans/x*(x-1);
	}
	return ans;
}
ll power(ll b)
{
	ll ans=1;
	ll a=2;
	while(b)
	{
		if(b&1)
		ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;	
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>s;
		ll ans=0;
		ll p=ol(mod);
		int len=strlen(s);
		for(ll i=0;i<len;i++)
		ans=(ans*10+s[i]-'0')%p;
		ans+=p;
		printf("%lld\n",power(ans-1));
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值