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(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
随机推荐
- data-ng-hide指令用于隐藏或显示HTML元素
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- selenium学习总结
selenium主要用来做web自动化,分1.0和2.0两个版本,1.0包括selenium IDE.selenium Grid.selenium Remote Control,2.0在1.0的基础上 ...
- ethereum(以太坊)(十一)--字节数组(一)
pragma solidity ^0.4.0; contract byte1{ /* 固定大小字节数组(Fixed-size byte arrays) 固定大小字节数组可以通过bytes1,bytes ...
- PHP队列的实现
队列是一种特殊的线性表,它只允许在表的前端,可以称之为front,进行删除操作:而在表的后端,可以称之为rear进行插入操作.队列和堆栈一样,是一种操作受限制的线性表,和堆栈不同之处在于:队列是遵循“ ...
- stark组件(4):列表定义列,展示数据库数据
效果图: 一.Stark组件 stark/service/core_func.py from django.urls import re_path from django.shortcuts impo ...
- Pandas 索引和切片
Series和Datafram索引的原理一样,我们以Dataframe的索引为主来学习 列索引:df['列名'] (Series不存在列索引) 行索引:df.loc[].df.iloc[] 选择列 / ...
- proteus中蜂鸣器不响的原因
本文参考自https://blog.csdn.net/gin_love/article/details/51168369 此网站.在用proteus仿真报警电路时,发现蜂鸣器不响.后在网上找了 ...
- 27-Middleware管道介绍
1-Middleware管道介绍,. 如果匹配上/task,则界面只会显示i am task. public void Configure(IApplicationBuilder app, IHost ...
- Hadoop常用高级特性
HDFS HA HDFS HA(High Availability)高可用性 相同版本拷贝工具,分布式集群拷贝工具,使用MapReduce实现 DistCp Version2 Guide HFTP协议 ...
- Android面试收集录3 ContentProvider详解
1.ContentProvider简单介绍 1.1.定义 ContentProvider,即内容提供者属于Android的四大组件之一. 1.2.作用 进程间进行数据交互&共享,即跨进程通信. ...