ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1748. The Most Complex Number

I cannot detect error (WA1) Please help me :)
Posted by Mickkie 25 Aug 2013 20:09
#include<stdio.h>
#include<math.h>
#include<map>
using namespace std;
map<unsigned long long,int> M;

int Prime[30]={0,2,3,5,7},Pct=5;
void genprime(int);

int expP[30]={70},solVal[500],ctsol;
unsigned long long solKey[500];
void gensol(unsigned long long,int);
void arrange();

main()
{
    genprime(30);
    gensol(1,1);
    arrange();
    //for (int i=1;i<=ctsol;i++) printf("%lld %d\n",solKey[i],solVal[i]);

    int Test,id;
    unsigned long long n;
    scanf("%d",&Test);
    for (int t=1;t<=Test;t++)
    {
        scanf("%llu",&n);
        id=ctsol;
        while (solKey[id]>n) id--;
        printf("%llu %d\n",solKey[id],solVal[id]);
    }
}
void genprime(int K)
{
    int i,j;
    for (i=11;Pct<K;i+=2) {
        for (j=1;Prime[j]*Prime[j]<=i;j++)
            if (i%Prime[j]==0)
                break;
        if (Prime[j]*Prime[j]>i)
            Prime[Pct++]=i;
    }
    //for (int i=1;i<Pct;i++) printf("%d\t",Prime[i]);
}
void gensol(unsigned long long x,int pID)
{
    int i,pro=1;
    for (i=1;i<30;i++)
        pro*=expP[i]+1;
    M[x]=pro;

    if (log10(x)+log10(Prime[pID])<=18.3 && expP[pID]<expP[pID-1]) {
        expP[pID]++;
        gensol(x*Prime[pID],pID);
        expP[pID]--;
    }
    if (log10(x)+log10(Prime[pID+1])<=18.3 && expP[pID]!=0) {
        expP[pID+1]++;
        gensol(x*Prime[pID+1],pID+1);
        expP[pID+1]--;
    }
}
void arrange()
{
    map<unsigned long long,int>::iterator it;
    for (it=M.begin();it!=M.end();it++) {
        if (it->second > solVal[ctsol]) {
            ctsol++;
            solKey[ctsol]=it->first;
            solVal[ctsol]=it->second;
        }
    }
}