Spoj amr10i Recursion

Source: Internet
Author: User

DES: give you n pieces of stone. No more than 70. Divide them into n heaps. The number of stones in each heap is a product. How many numbers are there in the question? The final result can be divided into primes or primes multiplied by 1 in addition to 1. So you can find all the primes up to 70 and then deep search.

It's hard to feel good and hard to find.

#include <stdio.h>#include<iostream>#include<Set>using namespacestd;intprime[ +] = {2,3,5,7, One, -, -, +, at, in, to,Panax Notoginseng, A, +, -, -, -, A, the, in, the};Set<Long Long>s;intp;voidDfsintXintNLong LongJi//do you want to count the number of x? What the current value is. What is the current product ?{S.insert (JI); if(Prime[x] > N)return; DFS (x+1, N, Ji);//do not take the first x primeDFS (x, n-prime[x], ji*prime[x]%p);//Take number x}intMain () {intT; CIN>>T;  while(t--)    {        intN; CIN>> N >>p;        S.clear (); DFS (0N1); cout<< s.size () <<Endl; }    return 0;}
L Oh, oh, K .

Spoj amr10i Recursion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.