Skip to main content
added 142 characters in body
Source Link

Java - 183183 177 bytes

int p(int a,int b){int P,c,t,l=P=t=a,f=0;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0)c++;a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

183 bytes

int p(int a,int b){int P,c,t,l,f=0;P=t=l=a;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0){c++;}a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

Ungolfed

int p(int a, int b){
    int P,c,t,ll=P=t=a,f=0;
    P=t=l=a;
    double p;
    while (P>0){
        a=t=l;
        c=0;
        while (t>0){
            if (a-(p=Math.pow(t, b))>=0 && t<=P){
                while((a-=p)>=0){
                    c++;
                }
                a+=p;
            }
            t--;
        }
        f=c<f||f==0?c:f;
        P--;
    }
    return f;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

Java - 183 bytes

int p(int a,int b){int P,c,t,l,f=0;P=t=l=a;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0){c++;}a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

Ungolfed

int p(int a, int b){
    int P,c,t,l,f=0;
    P=t=l=a;
    double p;
    while (P>0){
        a=t=l;
        c=0;
        while (t>0){
            if (a-(p=Math.pow(t, b))>=0 && t<=P){
                while((a-=p)>=0){
                    c++;
                }
                a+=p;
            }
            t--;
        }
        f=c<f||f==0?c:f;
        P--;
    }
    return f;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

Java - 183 177 bytes

int p(int a,int b){int P,c,t,l=P=t=a,f=0;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0)c++;a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

183 bytes

int p(int a,int b){int P,c,t,l,f=0;P=t=l=a;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0){c++;}a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

Ungolfed

int p(int a, int b){
    int P,c,t,l=P=t=a,f=0;
    double p;
    while (P>0){
        a=t=l;
        c=0;
        while (t>0){
            if (a-(p=Math.pow(t, b))>=0 && t<=P){
                while((a-=p)>=0)c++;
                a+=p;
            }
            t--;
        }
        f=c<f||f==0?c:f;
        P--;
    }
    return f;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9
added 40 characters in body
Source Link

THIS DOES NOT WORK FOR SOME VALUES.. IF YOU HAVE A CLUE PLEASE HELP

Java - 124183 bytes

int p(int a,int b){int c=0P,t=a;doublec,t,l,f=0;P=t=l=a;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0>=0&&t<=P){while((a-=p)>=0){c++;}a+=p;}t--;}f=c<f||f==0?c:f;P--;}return c+=a;f;}

Ungolfed

int p(int a, int b){
    int c=0P,t=a;c,t,l,f=0;
    P=t=l=a;
    double p;
    while (P>0){
        a=t=l;
        c=0;
        while (t>0){
            if (a-(p=Math.pow(t, b))>=0 && t<=P){
                while((a-=p)>=0){
                    c++;
                }
                a+=p;
            }
            t--;
        }
        f=c<f||f==0?c:f;
        P--;
    }
    return c+=a;f;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

THIS DOES NOT WORK FOR SOME VALUES.. IF YOU HAVE A CLUE PLEASE HELP

Java - 124 bytes

int p(int a,int b){int c=0,t=a;double p;while(t>0){if(a-(p=Math.pow(t,b))>=0){while((a-=p)>=0){c++;}a+=p;}t--;}return c+=a;}

Ungolfed

int p(int a, int b){
    int c=0,t=a;
    double p;
    while (t>0){
        if (a-(p=Math.pow(t, b))>=0){
            while((a-=p)>=0){
                c++;
            }
            a+=p;
        }
        t--;
    }
    return c+=a;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

Java - 183 bytes

int p(int a,int b){int P,c,t,l,f=0;P=t=l=a;double p;while(P>0){a=t=l;c=0;while(t>0){if(a-(p=Math.pow(t,b))>=0&&t<=P){while((a-=p)>=0){c++;}a+=p;}t--;}f=c<f||f==0?c:f;P--;}return f;}

Ungolfed

int p(int a, int b){
    int P,c,t,l,f=0;
    P=t=l=a;
    double p;
    while (P>0){
        a=t=l;
        c=0;
        while (t>0){
            if (a-(p=Math.pow(t, b))>=0 && t<=P){
                while((a-=p)>=0){
                    c++;
                }
                a+=p;
            }
            t--;
        }
        f=c<f||f==0?c:f;
        P--;
    }
    return f;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9
added 100 characters in body
Source Link

THIS DOES NOT WORK FOR SOME VALUES.. IF YOU HAVE A CLUE PLEASE HELP

Java - 124 bytes

int p(int a,int b){int c=0,t=a;double p;while(t>0){if(a-(p=Math.pow(t,b))>=0){while((a-=p)>=0){c++;}a+=p;}t--;}return c+=a;}

Ungolfed

int p(int a, int b){
    int c=0,t=a;
    double p;
    while (t>0){
        if (a-(p=Math.pow(t, b))>=0){
            while((a-=p)>=0){
                c++;
            }
            a+=p;
        }
        t--;
    }
    return c+=a;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

Java - 124 bytes

int p(int a,int b){int c=0,t=a;double p;while(t>0){if(a-(p=Math.pow(t,b))>=0){while((a-=p)>=0){c++;}a+=p;}t--;}return c+=a;}

Ungolfed

int p(int a, int b){
    int c=0,t=a;
    double p;
    while (t>0){
        if (a-(p=Math.pow(t, b))>=0){
            while((a-=p)>=0){
                c++;
            }
            a+=p;
        }
        t--;
    }
    return c+=a;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9

THIS DOES NOT WORK FOR SOME VALUES.. IF YOU HAVE A CLUE PLEASE HELP

Java - 124 bytes

int p(int a,int b){int c=0,t=a;double p;while(t>0){if(a-(p=Math.pow(t,b))>=0){while((a-=p)>=0){c++;}a+=p;}t--;}return c+=a;}

Ungolfed

int p(int a, int b){
    int c=0,t=a;
    double p;
    while (t>0){
        if (a-(p=Math.pow(t, b))>=0){
            while((a-=p)>=0){
                c++;
            }
            a+=p;
        }
        t--;
    }
    return c+=a;
}

Result

System.out.println(p(7, 2));    // 4
System.out.println(p(4,2));     // 1
System.out.println(p(7,3));     // 7
System.out.println(p(23,3));    // 9
Source Link
Loading