Hihocoder Challenge 11 Puzzle game

Source: Internet
Author: User

Title Link: http://hihocoder.com/problemset/problem/1165


Surface:

Puzzle game time limit:20000msSingle Point time limit:1000msMemory Limit:256MB
Describe

Fragrance today is in a good mood, and the flowers in the field of insects play a puzzle game.
This game is like this, for an array A, fragrance Select a number a from a, insects select a number b from a. A and B can be the same. Their score is the number of a*b factors.
The delicate fragrance and the worm of course want to get as high a score as possible, can you tell them which two number to choose?
Since the fragrance is a very casual person, the elements in array A are randomly chosen by her.

Input

A row of number N, which represents the number of integers in a.
The next line of N counts, representing a1, a2,..., an, is the element in a.

n <= 100000, 1 <= ai <= 100000
Ensure that all aI are randomly generated.

Output

A row represents the maximum score.

Sample input
23 4
Sample output
6

Problem solving: In the daytime just study the next prime number decomposition problems, just take the code to set up just right. First Take t-shirt, just good card in the end, yesterday also because Miss T-shirt sad, today for the first time got T-shirt happy to explode Ah!! The next step is to brush the quality of the problem, hoping to improve.

Still no nonsense, say this problem. The number of factors in a number equals the result of multiplying the number of each mass by the sum of its total decomposition into prime number. For example 75=3*5*5, then it has a factor of (+) * (2+1) = 6. In fact, this conclusion is particularly good proof that each factor number can take 0 to its number. For example, each takes 0, so the result is 1. If each is taken, then the result is the number itself. Pre-processing the number of factors in the 1-100000, and then the number of reading in order by the number of factors, and then take its first n (when n<200) or the first 200 calculations, take the maximum value.


Code:

#include <iostream> #include <map> #include <cmath> #include <algorithm>using namespace Std;map <int,int> store;bool is_prime (unsigned int x) {if (x==1) return False;else if (x==2) return true;int y=sqrt (1.0*x); for (int i=2;i<=y;i++) {if (x%i==0) return false;} return true;} void cal (unsigned int x) {if (Is_prime (x)) Store[x]++;else{int y=sqrt (1.0*x); for (int i=2;i<=y;i++) {if (x%i==0) {cal (I ); Cal (x/i); break;}}}} int ans[100005];struct info{int Key,val;} Tempstore[100005];bool CMP (Info a,info b) {return a.val>b.val;}  int main () {ans[1]=1;  ans[2]=2;  ans[3]=2;  int Tmp,res,maxx;    for (int i=4;i<=100000;i++) {Res=1;    Store.clear ();    int up_limit=sqrt (1.0*i);    Tmp=i;    for (int j=2;j<=up_limit;j++) {if (tmp%j==0) {cal (j); Cal (tmp/j);   }} if (Store.size () ==0) {ans[i]=2; Continue     } map <int,int>:: iterator iter;     For (Iter=store.begin (); Iter!=store.end (); iter++) res*= ((Iter->second) +1); ans[i]=Res;}  int N;while (cin>>n) {maxx=0;    for (int i=0;i<n;i++) {cin>>tmp;    tempstore[i].key=tmp;    TEMPSTORE[I].VAL=ANS[TMP];    } sort (tempstore,tempstore+n,cmp);    int z=min (200,N); for (int i=0;i<z;i++) {for (int m=0;m<z;m++) {Long Long w= ((Long long int) tempstore[i].key) *temps      Tore[m].key;        Store.clear ();        Res=1;        int up_limit=sqrt (1.0*W);       cout<< "*\n";   for (int j=2;j<=up_limit;j++) {if (w%j==0) {cal (J);   Cal ((int) w/j);      Break         }}//cout<< "@\n";  if (Store.size () ==0) {res=2;         } map <int,int>:: iterator iter;         For (Iter=store.begin (); Iter!=store.end (); iter++) res*= ((Iter->second) +1);         if (Res>maxx) maxx=res;      cout<< "&\n"; }} Cout<<maxx<<endl;} return 0;}


Hihocoder Challenge 11 Puzzle game

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.