ZOJ 2562 more divisors (high synthesis number)

Source: Internet
Author: User

ZOJ 2562 more divisors (high synthesis number)

ACM

Title Address: ZOJ 2562 more divisors

Test Instructions :
Find the largest high synthetic number less than n, a high synthetic number refers to a class of integers, no matter what the number of natural number is smaller than the number of factors.

Analysis :
On the internet called it anti-Prime, in fact I checked, the number of the number should be written backwards write is the prime number of prime. This is supposed to be called a high synth, see wikipedia:highly composite number.

The high composition number has the following characteristics:
where p 1 < p 2 <?< p k Is prime, and the exponents c i is positive integers.
Any factor of n must has the same or lesser multiplicity in each prime:
P1^d1x P2^d 2 x?x Pk^d k , 0≤ d i ≤ c i , 0<I≤k
So use backtracking enumeration.

Code :

/** Author:illuz <iilluzen[at]gmail.com>* blog:http://blog.csdn.net/hcbbt* file:2562.cpp* Create date:2014-08-06 20:45:53* descripton:highly Composite number*/#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define REPF (I,A,B) for (int i= (a); i<= (b); i++ typedef long LONG ll;const int M = 1000;ll n;ll bestnum;ll bestsum;ll hcm[m][2];ll prim[] = {2, 3, 5, 7, 11, 13, 17, 19,  23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}; Current is num, with the prim[k], sum of divisors, the limit of prim[k] you can usevoid getnum (ll num, int k, ll sum, in T limit) {if (sum > bestsum) {bestsum = Sum;bestnum = num;} else if (sum = = bestsum && num < bestnum) {BESTN Um = num;}  ll p = prim[k];for (int i = 1; I <= limit; i++, p *= prim[k]) {//Use I prim[k]sif (num * p > N) break;getnum (num *= Prim[k], k + 1, Sum * (i + 1), i);}} Clac log2 (n) int log2 (ll n) {int ret = 0;ll p = 1;while (P < n) {p <<= 1;ret++;} return ret;} Return the number of highly Composite number in [1, n]//and save the HCM in Hcm[][2]int gethcm () {int ret = 0;n = 5000  00;//[1, n]while (n > 0) {bestnum = 1;bestsum = 1;getnum (1, 0, 1, log2 (n)); cout << bestnum << ' << Bestsum << endl;hcm[ret][0] = bestnum;hcm[ret][1] = Bestsum;n = bestnum-1;ret++;} return ret;} int main () {while (CIN >> n) {bestnum = 1;bestsum = 1;getnum (1, 0, 1, +); cout << bestnum << Endl;}}


ZOJ 2562 more divisors (high synthesis number)

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.