I - Dividing Stones
Description
There are N stones, which can be divided into some piles arbitrarily. Let the value of each division be equal to the product of the number of stones in all the piles modulo P. How many possible distinct values are possible for a given N and P?
INPUT
The
first line contains the number of test cases T. T lines follow, one
corresponding to each test case, containing 2 integers: N and P.
OUTPUT
Output T lines, each line containing the required answer for the corresponding test case.
CONSTRAINTS
T <= 20
2 <= N <= 70
2 <= P <= 1e9
SAMPLE INPUT
2
3 1000
5 1000
SAMPLE OUTPUT
3
6
EXPLANATION
In
the first test case, the possible ways of division are (1,1,1), (1,2),
(2,1) and (3) which have values 1, 2, 2, 3 and hence, there are 3
distinct values.
In the second test case, the numbers 1 to 6 constitute the answer and they can be obtained in the following ways:
1=1*1*1*1*1
2=2*1*1*1
3=3*1*1
4=4*1
5=5
6=2*3
题意:n p 在1~~n内 寻找素数和等于n的 并且乘积不相等
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<set>
#include <iostream> using namespace std;
set<long>s;
int p[],mod,n,t;
bool vis[]; void prime()
{
int cnt=;
memset(vis,,sizeof(vis));
memset(p,,sizeof(p));
for(int i=; i<=; i++) ///素数打标 n很小 <=70 所以可以打表
{
if(vis[i])
{
p[++cnt]=i;
for(int j=i*i; j<=; j+=i)
vis[j]=;
// cout<<p[cnt-1]<<"~~~~~~~~~~~"<<endl;
} }
}
void dfs(int i,int x,long long ans)
{
s.insert(ans);
if (p[i]>x)
return;
dfs(i,x-p[i],ans*p[i]%mod); ///取第i个素数
dfs(i+,x,ans); ///深搜第i+1个素数
}
int main()
{
prime();
scanf("%d",&t);
while (t--)
{
s.clear();
scanf("%d%d",&n,&mod);
dfs(,n,);
printf("%d\n",s.size());
}
return ;
}
//dfs(x,n-pr[x],ji*pr[x]%p);//取第x个素数
//dfs(x+1,n,ji);//从第x+1个素数深搜
I - Dividing Stones的更多相关文章
- SPOJ AMR10I Dividing Stones --DFS
题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况. 分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为 ...
- SPOJ AMR10I Dividing Stones
Time limit: 7s Source limit: 50000B Memory limit: 256MB The first line contains the number of test c ...
- UVa 12525 Boxes and Stones (dp 博弈)
Boxes and Stones Paul and Carole like to play a game with S stones and B boxes numbered from 1 to B. ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- CF 371B Fox Dividing Cheese[数论]
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- AC日记——Dividing poj 1014
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69575 Accepted: 18138 Descri ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- 动态规划--模板--hdu 1059 Dividing
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- fedora25的nfs文件系统搭建
关于NFS的原理介绍可以参考这篇文章:http://blog.51cto.com/atong/1343950 1> nfs服务端 安装nfs工具包和rpcbind包 dnf install nf ...
- BZOJ2330或洛谷3275 [SCOI2011]糖果
BZOJ原题链接 洛谷原题链接 很明显的差分约束,但数据范围较大,朴素\(SPFA\)判正环求解会\(T\)(理论上如此,但我看到有挺多人用朴素的还跑得挺快..),所以需要优化. 我们所建立的有向图中 ...
- UI设计教程分享:让你彻底读懂字体
一份普普通通.规规矩矩的设计 一份让人印象深刻.新颖有趣的设计 差在哪?其实就差在三个字上! “优秀的设计不是每一个细节都有亮点,而是弱化其他元素,让某一个亮点最大化.” 今天“骉叔的设计心得”就来总 ...
- [FreeMind] 绘制思维时遇到的常见问题解决办法
如何改变节点的摆放方向? 如果是新建节点,选择要放置节点的那一侧,按enter键,或者鼠标右键,插入平行节点即可. 如果是已经建好的节点,可以用ctrl+x, ctrl+v粘贴到另一边,或者选中子节点 ...
- xcode资源管理
1. 在根目录放图片. UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ok.pn ...
- 使用scrollTop返回顶部
scrollTop属性表示被隐藏在内容区域上方的像素数.元素未滚动时,scrollTop的值为0,如果元素被垂直滚动了,scrollTop的值大于0,且表示元素上方不可见内容的像素宽度 由于scrol ...
- Win 10 关闭了.net framework 3.5后再开启不成功
背景: Win10 想要使用IETester来测试下页面的浏览器兼容性.在“控制面板”里关闭了.net framework 3.5,再重新开启. 问题: 在重新开启的时候,提示不成功.错误代码0x80 ...
- Aspose.Words给word文档加水印
需求:在一些重要的Word文档需要打印时,添加水印以明出处. 方案:使用Aspose组件给word文档 代码:干货如下 /// <summary> /// Inserts a waterm ...
- HTML 学习杂记
代码范例 <?php function testFunc1 () { echo 'testFunc1'; } $b = ; ?> <!DOCTYPE html PUBLIC &quo ...
- .Net 导出Excel时设置单元格的格式为文本类型
<td style= 'vnd.ms-excel.numberformat:@ ' align='right'>" & Format(Val(rowTitle.Item( ...