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. UOJ 274 温暖会指引我们前进 - LCT

    Solution 更新掉路径上温暖度最小的边就可以了~ Code #include<cstdio> #include<cstring> #include<algorith ...

  2. error C4996: 'GetVersionExW': 被声明为已否决

    1.Project Properties > Configuration Properties > C/C++ > General > SDL checks关掉 其他方法:2. ...

  3. 补课:Shell命令${}

    Shell中的${}.##和%%使用范例: 代码如下:file=/dir1/dir2/dir3/my.file.txt可以用${ }分别替换得到不同的值:${file#*/}:删掉第一个 / 及其左边 ...

  4. 新手必看,史上最全的iOS开发教程集锦,没有之一!

    最近大火的iPhone XS Max和iPhone XS,不知道有没有同学已经下手了呢?一万三的价位确实让很多人望而却步啊.据说为了赢得中国的用户,专门出了双卡双待的,可想而知中国市场这块“肥肉”人人 ...

  5. MySQL open_files_limit相关设置

    背景:      数据库链接不上,报错: root@localhost:/var/log/mysql# mysql -uzjy -p -h192.168.1.111 --default-charact ...

  6. python学习 day6 (3月7日)

    #__author : 'liuyang' #date : 2019/3/7 0007 a = ['a' , 'b' , 'c'] b = [] print(a is b ) # 空元组 可以 空列表 ...

  7. 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows

    https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...

  8. python中的函数嵌套

    一.函数嵌套 1.只要遇到了()就是函数的调用.如果没有就不是函数的调用 2.函数的执行顺序 遵循空间作用域,遇到调用才执行 def outer(): def inner(): print(" ...

  9. 爬取微博的数据时别人用的是FM.view方法传递html标签那么jsoup怎么解析呢

    使用JSOUP就行 这里给出点思路 我只做了自己的首页和其他人的微博首页的抓取 其他的抓取没尝试(不好意思 比较懒...) 首先是利用JSOUP进行登陆 获取页面 看了下微博的登陆表格 发现用了aja ...

  10. vue +bootstrap 写的小例子

    最近vue挺火,最近也不是特别忙,就学习了下. vue和angular非常像都是MVVM.道理都是想通的,就是语法的差异 我觉得vue和angular区别: 1.vue更轻,更便捷,适用于移动开发 2 ...