题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况。

分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为2*2*1,所以就可以枚举素因子来分解,dfs即可。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;
#define N 100007 int prime[] = {, , , , , , , , , , , , , , , , , , , };
int n,p;
set<ll> ans; void dfs(int ind,int now,ll num)
{
ans.insert(num);
if(now < prime[ind])
return;
dfs(ind,now-prime[ind],num*prime[ind]%p); //分解这个
dfs(ind+,now,num); //不分解这个
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&p);
ans.clear();
dfs(,n,);
printf("%d\n",ans.size());
}
return ;
}

最新文章

  1. Wiki语料处理
  2. 多个div居中显示
  3. 团队项目——站立会议 DAY8
  4. 15个IT技术人员必须思考的问题
  5. DELPHI7在WIN8和WIN10下安装和运行
  6. 15个实用的jQuery技术
  7. AM335x(TQ335x)学习笔记——挂载Ramdisk
  8. Android NDK 环境搭建 + 测试例程
  9. 10. Regular Expression Matching
  10. python_求1-2+3-4+......-100的值
  11. Hibernate进阶知识点必备
  12. C. New Year and Rating 差分方程 思维
  13. luogu准备复习(学习)题单
  14. &quot;Loading a plug-in failed The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled&quot;
  15. RDD内存迭代原理(Resilient Distributed Datasets)---弹性分布式数据集
  16. Linux添加防火墙、iptables的安装和配置(亲测)
  17. 打包python为可执行文件时报错R6034解决方案
  18. 配置consul为windows服务
  19. git untrack file
  20. git服务器-------》用户免密git操作

热门文章

  1. SpringMVC中出现&quot; 400 Bad Request &quot;错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
  2. 常用SQL语句优化技巧
  3. ajax跨子域请求的两种现代方法
  4. Android Xutils 框架(转)
  5. Orchard源码:Logging
  6. HTML5中的音视频处理
  7. .net学习总结
  8. 实现跨域的N种方法
  9. C语言复习
  10. cornerstone 使用