SPOJ AMR10I Dividing Stones
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
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
#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的更多相关文章
- SPOJ AMR10I Dividing Stones --DFS
题意:给n个石头,分成一些部分(最多n部分,随便分),问分完后每部分的数量的乘积有多少种情况. 分析:可以看出,其实每个乘积都可以分解为素数的乘积,比如乘积为4,虽然可以分解为4*1,但是更可以分解为 ...
- I - Dividing Stones
Description There are N stones, which can be divided into some piles arbitrarily. Let the value of e ...
- SPOJ AMR10I 递归
DES :给你n 块石头.不会超过70.把它们分成n堆.每堆里的石头数做积.问共有多少个数.最终的结果除了1之外都能分解成素数相乘或者素数相乘再乘1.所以可以找到所有不超过70的素数然后进行深搜. 感 ...
- Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 88[Submi ...
- 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. ...
- 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 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- 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 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
随机推荐
- 头部导航悬浮,css
.header{ position:fixed; z-index:100; left:; right:; } 如图.
- C/C++获取本机名+本机IP+本机MAC
本机名.IP.MAC都是一些比较常用网络参数,怎么用C/C++获取呢? 研究了两三个小时... 需要说明的都在代码注释里 #include <stdio.h> #include <W ...
- Java - 静态方法的线程安全问题
若该静态方法中有对某个静态属性操作,那么它就不是线程安全的,反之,若只对实例属性操作,那么它就是线程安全的. 补充说明,因为,静态方法不对特定的实例操作,只能访问静态成员.实例方法可对特定的实 ...
- Centos7上搭建activemq集群和zookeeper集群
Zookeeper集群的搭建 1.环境准备 Zookeeper版本:3.4.10. 三台服务器: IP 端口 通信端口 10.233.17.6 2181 2888,3888 10.233.17.7 2 ...
- java数组之二分法查找
认识: 猜字游戏 步数 所猜的数 结果 可能值的范围 0 1~100 1 50 太高 1~49 2 25 太低 26~49 3 37 太高 26~36 4 31 太低 32~36 5 34 太 ...
- PHP自动生成分页链接
page.class.php <?php class Page { // 分页栏每页显示的页数 public $rollPage = 5; // 页数跳转时要带的参数 public $param ...
- 【c学习-2】
#include <stdio.h> #define MYVAR 18 int main(){ //float x=3.14; //x=3.14++; //printf("%c\ ...
- python__高级 : @修饰器(装饰器)的理解
以下是第一次了解的时候写的东西,有的地方理解不正确,虽已改正但是太片面,请直接看下面第二次修改加上的内容. ---------------------------------------------- ...
- 以CentOS为操作系统的vps或服务器安装lnmp运行环境的方法
安装步骤: 1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum ...
- tp5简单构造
application 应用目录 网站核心index前台目录 controller 控制器admin 后台目录 model 数据模型view 视图extend 静态类库目录public 静态资源和入口 ...