Time limit: 7s Source limit: 50000B Memory limit: 256MB

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



 
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个石子,可以分成任意堆,每一种分法的值为每一堆的石子数量的乘积。求一共可以分成多少个不同的乘积。
分析:最终的乘积除了1以外,都可以分解成素数相乘或者素数相乘再与1相乘的形式。因为n不超过70,所以我们可以先找出不超过70的所有素数,然后从这些素数中进行搜索求解即可。为了方便求出不同的乘积有多少个,可以用STL里面的set来统计不同的数有多少个。
 
 
 
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
set<LL> s;
int prime[] = {, , , , , , , , , , , , , , , , , , , , };
int n, p; void dfs(int num, int cur, LL ans)
{
s.insert(ans);
if(cur < prime[num]) return ;
dfs(num, cur - prime[num], ans * prime[num] % p); //要第num个素数
dfs(num+, cur, ans); //不要第num个素数
} int main()
{
int T, i, j;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&p);
s.clear();
dfs(, n, );
printf("%d\n", s.size());
}
printf("\n");
}

SPOJ AMR10I Dividing Stones的更多相关文章

  1. SPOJ AMR10I Dividing Stones --DFS

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

  2. I - Dividing Stones

    Description There are N stones, which can be divided into some piles arbitrarily. Let the value of e ...

  3. SPOJ AMR10I 递归

    DES :给你n 块石头.不会超过70.把它们分成n堆.每堆里的石头数做积.问共有多少个数.最终的结果除了1之外都能分解成素数相乘或者素数相乘再乘1.所以可以找到所有不超过70的素数然后进行深搜. 感 ...

  4. Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论

    1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 130  Solved: 88[Submi ...

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

  6. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  7. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  8. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  9. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

随机推荐

  1. 【洛谷P1323】删数问题

    删数问题 题目链接 首先找出最小的k个数:用堆每次取出最小的元素p,将p*2+1和p*4+5压入堆. 贪心求最大数:从前往后找第一个data[j+1]>data[j],删除data[j].(链表 ...

  2. Oracle SCN与时间的相互转换

    1.SCN转换成时间 select scn_to_timestamp(current_scn) from v$database; 2.时间转换成SCN select timestamp_to_scn( ...

  3. iOS 实时监测网络状态(通过Reachability)

    在AppDelegate.m中 @property (nonatomic, strong) Reachability *reach; - (BOOL)application:(UIApplicatio ...

  4. Mysql语句 AND 和 OR 的运用

    数据记录 查询方式1 -- 查询info=1或者info=2同时bookname=java的数据 AND bookname='java'; 查询方式2 -- 查询info=3同时bookname=ja ...

  5. MARK 一条关于Linux 运维方面个人向收藏网址

    吴钧泽博客 https://wujunze.com/archives.html Linux运维笔记 https://blog.linuxeye.cn/ Linux中文网 http://www.ppze ...

  6. Redis 数据类型List链表

    list类型是一个双向链表. 上进上出:栈 例1 lpush newlogin tom lpush newlogin  jim lpush newlogin php lpush newlogin th ...

  7. 【yii2】 yii框架如果控制器和方法都是多个单词组成应该怎样写请求链接

    最近的一个项目碰到这种问题,摸索出了解决办法,故此记录下 example 如果控制器为 ShopCollect 方法为 UserList solution 请求的链接应该为 doman.com/sho ...

  8. 关于ZYNQ-700是否支持大容量SD卡汇报

    关于ZYNQ-700是否支持大容量SD卡 不支持. 下午问了客服的FAE给的答案是不清楚,我自己调研了一下为什么. 调查结果: 1. 大容量的SD卡为什么不支持? SD2.0规范中(SDHC)硬件支持 ...

  9. Python基础-字符串的使用

    基础知识 字符串解释:字符串是不可变的,所有元素赋值和切片赋值操作都是非法的,属于序列一种(字符串.元组.列表). 一.格式化字符串 (1).format()方法==str.format() 作用:将 ...

  10. C#简单的文件阅读器

    写一个简单的文件阅读器  1.可以读取大文件(2G)2.实现首页.下一页.前一页.末页的跳转3.实现到指定页面的跳转,比如跳转到第**页4.限制每页显示字符数 1029-4069byte,且用户可自定 ...