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的更多相关文章

  1. SPOJ AMR10I Dividing Stones --DFS

    题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况. 分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为 ...

  2. SPOJ AMR10I Dividing Stones

    Time limit: 7s Source limit: 50000B Memory limit: 256MB The first line contains the number of test c ...

  3. 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. ...

  4. POJ 1014 Dividing

    Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...

  5. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  7. POJ 1014 Dividing(多重背包)

    Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collectio ...

  8. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  9. 动态规划--模板--hdu 1059 Dividing

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

随机推荐

  1. VirtualBox中安装Fedora9及其ARM开发环境配置

    因为要学习Tiny4412开发板的嵌入式编程,需要用到Fedora9系统(和手册对应),我就在VirtualBox虚拟机(此虚拟机安装在Ubuntu12.04上)上安装了Fedora9,下面就讲解一下 ...

  2. Python之路(第五篇) Python基本数据类型集合、格式化、函数

    一.变量总结 1.1 变量定义 记录某种状态或者数值,并用某个名称代表这个数值或状态. 1.2 变量在内存中的表现形式 Python 中一切皆为对象,数字是对象,列表是对象,函数也是对象,任何东西都是 ...

  3. vc项目中加载多个lib遇到的问题

    一个VC项目中 在网络加密 json解析等方面  加载了多个第三方库和文件 boost cryptpp rapidjson  mysql的连接池等等 在使用mysql++的时候 多次报错 LNK 20 ...

  4. android udp 无法收到数据 (模拟器中)

    解决方法:1. 运行模拟器2. 打开window 命令行执行:telnet localhost 55545554是模拟器的端口,执行之后会进入android console3. 在console下执行 ...

  5. EasyUI DataGrid 获得分页信息

    var b = $('#SBDiv_1_DateGrid').datagrid('options'); console.info(b); 具体需要哪些字段,可以通过火狐debug,然后自己找需要的信息 ...

  6. SpringBoot获取resource下证书失败

    1.第一种失败的情况:    本来使用Spring的上下文容器获取文件,将证书文件放在resource下,编译后获取文件会出现报错 java.security.spec.InvalidKeySpecE ...

  7. 斐波那契数列(NOIP1997)

    题目链接:斐波那契数列 这题是数论的一个基本应用,还是很水,因为数据范围太水了,只有48,这也太小了.不过也有可能是当时的电脑速度跑得比较慢的原因.但是这个算法应该还是这个算法.主要思路就是递推求斐波 ...

  8. 796. Rotate String

    class Solution { public: bool rotateString(string A, string B) { if(A.length()==B.length()&& ...

  9. 2019.02.09 codeforces451 E. Devu and Flowers(容斥原理)

    传送门 题意简述:给出n堆花,对于第j堆,有f[j]朵花,每堆花的颜色不同,现在要从中选出s朵,求方案数. 思路: 假设所有花没有上限直接插板法,现在有了上限我们用容斥扣掉多算的 状压一下再容斥:fi ...

  10. Query - noConflict() 方法

    ps:菜鸟教程 如何在页面上同时使用 jQuery 和其他框架? noConflict() 方法会释放对 $ 标识符的控制,这样其他脚本就可以使用它了. 当然,您仍然可以通过全名替代简写的方式来使用 ...