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. P1024 一元三次方程求解

    P1024 一元三次方程求解 #include<cstdio> #include<iostream> #include<algorithm> using names ...

  2. Informatica 简单使用

    1. Informatica简介 ① Repository manager 主要用来维护资料库的目录,对象,建完对象可以创建demo的folder. ② Administration Console是 ...

  3. RestKit ,一个用于更好支持RESTful风格服务器接口的iOS库

    简介 RestKit 是一个用于更好支持RESTful风格服务器接口的iOS库,可直接将联网获取的json/xml数据转换为iOS对象. 项目主页: RestKit 最新示例: 点击下载 注意: 如果 ...

  4. Webpack4 学习笔记一初探Webpack

    前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 Webpack 打包文件 支持JS模块化 模式: production(0配置默认), development(生产环境) 更详细的 ...

  5. BZOJ4128: Matrix(BSGS 矩阵乘法)

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 813  Solved: 442[Submit][Status][Discuss] Descriptio ...

  6. 微信网页授权access_token与基础支持的access_token

    问题1:网页授权access_token与分享的jssdk中的access_token一样吗? 答:不一样.网页授权access_token 是一次性的,而基础支持的access_token的是有时间 ...

  7. Oracle_11g中解决被锁定的scott用户的方法

    在安装完Oracle10g和创建完oracle数据库之后,想用数据库自带的用户scott登录,看看连接是否成功. 问题: 在cmd命令中,用“sqlplus  scott/ tiger”登录时,老是提 ...

  8. python__高级 : GC垃圾回收相关

    python的垃圾回收机制是以引用计数为主,加上标记-清除,分代收集等辅助方式组成的,如果想打开gc功能,需要 import gc 模块 ,然后 gc.enable() 就打开了这个功能,关闭是 gc ...

  9. python -- 输出异常详细信息

    在使用try:  except:  捕获异常后,想要获取到异常信息的详细内容另做它用,可以使用python的内置模块traceback进行获取. traceback.print_exc() 直接打印异 ...

  10. Codeforces Round 97B 点分治

    B. Superset time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...