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

HELP ME!!!!!!! WA8 - I think the correct solution; WA11 - I think not the correct solution; WHY? ??
Posted by ANDREY TRUBIN 10 Jul 2011 17:10
WA 8
#include <iostream>
#include <math.h>
using namespace std;
long long h[104680];
int main(){
    int wr,a2,a3,a5,a7,a11,a13,a17,a19,a23,a29,a31,a37,i,t;
    long long p,u,f1,c1,e,k,n,g,c,f,b2,b3,b5,b7,b11,b13,b17,b19,b23,b29,b31,b37,j;

    for (i=1;i<=104000;i++)h[i]=1000000000000000011;
    for (a2=0;a2<=8;a2++){
        b2=powf(2,a2);
        for (a3=0;a3<=4;a3++){
            if (a2<a3)break;
            b3=b2*powf(3,a3);
            for (a5=0;a5<=3;a5++){
                if (a2<a5)break;
                b5=b3*powf(5,a5);
                for (a7=0;a7<=2;a7++){
                    if (a2<a7)break;
                    b7=b5*powf(7,a7);
                    for (a11=0;a11<=1;a11++){
                        if (a2<a11)break;
                        b11=b7*powf(11,a11);
                        for (a13=0;a13<=1;a13++){
                            if (a2<a13)break;
                            b13=b11*powf(13,a13);
                            for (a17=0;a17<=1;a17++){
                                if (a2<a17)break;
                                b17=b13*powf(17,a17);
                                for (a19=0;a19<=1;a19++){
                                    if (a2<a19)break;
                                    b19=b17*powf(19,a19);
                                    for (a23=0;a23<=1;a23++){
                                        if (a2<a23)break;
                                        b23=b19*powf(23,a23);
                                        for (a29=0;a29<=1;a29++){
                                            if (a2<a29)break;
                                            b29=b23*powf(29,a29);
                                            for (a31=0;a31<=1;a31++){
                                                if (a2<a31)break;
                                                b31=b29*powf(31,a31);
                                                for (a37=0;a37<=1;a37++){
                                                    k=b31*powf(37,a37);

                                                    g=(a2+1)*(a3+1)*(a5+1)*(a7+1)*(a11+1)*(a13+1);
                                                    g=g*(a17+1)*(a19+1)*(a23+1)*(a29+1)*(a31+1)*(a37+1);
                                                    if (g<=103680){
                                                        if ((0<k)&&(k<h[g])){
                                                            h[g]=k;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cin >> t;
    for (i=1;i<=t;i++){
        cin >> n;
        f1=0;c1=0;
        for (j=1;j<=103680;j++){
            if (h[j]<=n){
                f1=h[j];
                c1=j;
            }
        }
        cout << f1 << " " << c1 << endl;
    }
    cin >> i;
    return 0;
}






WA 11
#include <iostream>
#include <math.h>
//#include <fstream>
//#include <ctime>
using namespace std;
int main(){
    int a2,a3,a5,a7,a11,a13,a17,a19,a23,a29,a31,a37,i,t;
    long long k,n,g,c,f,b2,b3,b5,b7,b11,b13,b17,b19,b23,b29,b31,b37;
    //ifstream f1("1.txt");
    cin >> t;//clock_t t0 = clock();
    for (i=1;i<=t;i++){
    cin >> n;
    c=1;
    f=1;
    if (n>1000000000000){
    for (a2=4;a2<=9;a2++){
        b2=powf(2,a2);
        for (a3=1;a3<=5;a3++){
            if (a2<a3)break;
            b3=b2*powf(3,a3);
            for (a5=1;a5<=4;a5++){
                if (a2<a5)break;
                b5=b3*powf(5,a5);
                for (a7=1;a7<=3;a7++){
                    if (a2<a7)break;
                    b7=b5*powf(7,a7);
                    for (a11=1;a11<=2;a11++){
                        if (a2<a11)break;
                        b11=b7*powf(11,a11);
                        for (a13=0;a13<=1;a13++){
                            if (a2<a13)break;
                            b13=b11*powf(13,a13);
                            for (a17=0;a17<=1;a17++){
                                if (a2<a17)break;
                                b17=b13*powf(17,a17);
                                for (a19=0;a19<=1;a19++){
                                    if (a2<a19)break;
                                    b19=b17*powf(19,a19);
                                    for (a23=0;a23<=1;a23++){
                                        if (a2<a23)break;
                                        b23=b19*powf(23,a23);
                                        for (a29=0;a29<=1;a29++){
                                            if (a2<a29)break;
                                            b29=b23*powf(29,a29);
                                            for (a31=0;a31<=1;a31++){
                                                if (a2<a31)break;
                                                b31=b29*powf(31,a31);
                                                for (a37=0;a37<=1;a37++){
                                                    k=b31*powf(37,a37);

                                                    g=(a2+1)*(a3+1)*(a5+1)*(a7+1)*(a11+1)*(a13+1);
                                                    g=g*(a17+1)*(a19+1)*(a23+1)*(a29+1)*(a31+1)*(a37+1);
                                                    if ((((k<=n) && (c<g))||((k<f) && (c==g)))&&(k>0)){
                                                        c=g;
                                                        f=k;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //lkj3:;
        }
    }
    cout << f << " " << c << endl;
    }
    else {
        if (n>1000000){
    for (a2=2;a2<=8;a2++){
        b2=powf(2,a2);
        for (a3=1;a3<=4;a3++){
            if (a2<a3)break;
            b3=b2*powf(3,a3);
            for (a5=1;a5<=3;a5++){
                if (a2<a5)break;
                b5=b3*powf(5,a5);
                for (a7=0;a7<=2;a7++){
                    if (a2<a7)break;
                    b7=b5*powf(7,a7);
                    for (a11=0;a11<=1;a11++){
                        if (a2<a11)break;
                        b11=b7*powf(11,a11);
                        for (a13=0;a13<=1;a13++){
                            if (a2<a13)break;
                            b13=b11*powf(13,a13);
                            for (a17=0;a17<=1;a17++){
                                if (a2<a17)break;
                                b17=b13*powf(17,a17);
                                for (a19=0;a19<=1;a19++){
                                    if (a2<a19)break;
                                    b19=b17*powf(19,a19);
                                    for (a23=0;a23<=1;a23++){
                                        if (a2<a23)break;
                                        b23=b19*powf(23,a23);
                                        for (a29=0;a29<=1;a29++){
                                            if (a2<a29)break;
                                            b29=b23*powf(29,a29);
                                            for (a31=0;a31<=1;a31++){
                                                if (a2<a31)break;
                                                k=b29*powf(31,a31);
                                        g=(a2+1)*(a3+1)*(a5+1)*(a7+1)*(a11+1)*(a13+1);
                                        g=g*(a17+1)*(a19+1)*(a23+1)*(a29+1)*(a31+1);
                                        if (((k<=n) && (c<g))||((k<f) && (c==g))){
                                        c=g;
                                        f=k;
                                        }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //lkj3:;
        }

    }
    cout << f << " " << c << endl;
        } else {
    for (a2=0;a2<=7;a2++){
        b2=powf(2,a2);
        for (a3=0;a3<=4;a3++){
            if (a2<a3)break;
            b3=b2*powf(3,a3);
            for (a5=0;a5<=2;a5++){
                if (a2<a5)break;
                b5=b3*powf(5,a5);
                for (a7=0;a7<=2;a7++){
                    if (a2<a7)break;
                    b7=b5*powf(7,a7);
                    for (a11=0;a11<=1;a11++){
                        if (a2<a11)break;
                        b11=b7*powf(11,a11);
                        for (a13=0;a13<=1;a13++){
                            if (a2<a13)break;
                            b13=b11*powf(13,a13);
                            for (a17=0;a17<=1;a17++){
                                if (a2<a17)break;
                                k=b13*powf(17,a17);
                                        g=(a2+1)*(a3+1)*(a5+1)*(a7+1)*(a11+1)*(a13+1);
                                        g=g*(a17+1);
                                        if (((k<=n) && (c<g))||((k<f) && (c==g))){
                                        c=g;
                                        f=k;
                                        }
                            }
                        }
                    }
                }
            }
            //lkj3:;
        }

    }
    cout << f << " " << c << endl;
        }
    }

    }//clock_t t1 = clock();cout << "time: " << (double)(t1 - t0) / CLOCKS_PER_SEC << endl;
    cin >> i;
    return 0;
}
AC!!!!!!!!!!
Posted by ANDREY TRUBIN 10 Jul 2011 23:11
Solved 15 hours!!!!!!!!!!!!!!!!!!!!!!!!

long long < 2^63          Received overflow
On it received WA!!!!!!!!!


Edited by author 10.07.2011 23:16

Edited by author 10.07.2011 23:17

Edited by author 10.07.2011 23:17

Edited by author 10.07.2011 23:17
Re: HELP ME!!!!!!! WA8 - I think the correct solution; WA11 - I think not the correct solution; WHY? ??
Posted by Nikita Glashenko [Samara SAU] 27 Jul 2011 21:03
zomfg O_o_0