Ad
  • Custom User Avatar
  • Default User Avatar
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    got it! Seriously thanks for your immense help! I have a hard time imagining
    how I would have seen that without your help!

  • Default User Avatar

    You say you think it contains some specific information. Do you have any promise anywhere that tells you this is so? Or any indication at all? If you look at the example code you can see how it is used. It does not put this length information there, or any other information, but the parameter is used, what's done with it?

    Not required to answer that, but so that you have the full code - this is the preloaded function:
    (and if anyone's feeling trigger happy on the spoiler button - don't. there is nothing secret in this.)

    char* array2StringData(Pair** arr, int sz) {
        if (sz == 0) {free(arr); return "{}";}
        // for each pair length of 2 int + { + } +", " + 1
        int lgs = 0;
        for(int i = 0; i < sz; i++) {
            lgs += 10 + 10 + 5;
        }
        char *dest = (char*)calloc(1, sizeof(char) * lgs + 1);
        char *p = dest;
        *p++ = '{';
        for(int i = 0; i < sz; i++) {
            sprintf(p += strlen(p), "{%lld, %lld}", arr[i]->first, arr[i]->snd);
            //free the pair
            free(arr[i]); arr[i] = NULL;
        }
        // free array of pairs
        free(arr);
        int l = strlen(dest);
        dest[l] = '}'; dest[l + 1] = '\0';
        return dest;
    }
    
  • Default User Avatar

    As far as I can tell its the amount of pairs in the answer which is why I allocate the Pair** with that amount so the array of structs is that length.

  • Default User Avatar

    Reconsider what the length param is for. What promises are you given about it, how is it used in the test code?

  • Default User Avatar

    find a faster way to find divisors (maybe googling turns something up)

    you can also try finding divisors for some numbers manually, humans are optimizing problem solvers so you might .. optimize it and then do the same thing in your code

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    No, you still didn't understand me. You have to solve this WITHOUT calulcating factorial. Try running factorial_func(4000) and see how long it takes (spoiler: too long).

    I solved it long time ago, so I don't remember how, but I see I never calculated any factorials. This is more of a math problem.

    Also, when you post code, use it with proper formatting, otherwise we can't debug it with all indentation errors.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I don't know exactly where it's wrong, but I see that prime list doesn't contain 2, that's one of your problems (looks like incorrect ranges specified), but it's your task to debug it, not mine.

    Also, it looks like you're actually calculating the factorial itself. That's way too slow and not gonna work for bigger numbers. There's another way to solve it.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    i try to solving calculating the factorial of 12 and dividing by 12 but the result is really big, and dividing 12 by 2 is 6

    Why divide by 12? Why divide 12 by 2? Where are these calculations coming from?

    12 factorial is BIG number, that's why you can keep dividing it by 2 10 times, until it's not possible anymore. I don't think you quite understood this task...

  • Default User Avatar

    Hi!

    There is something that i dont understand. For example, factorial of 12 why is divisible by 2 10 times??!!?? i try to solving calculating the factorial of 12 and dividing by 12 but the result is really big, and dividing 12 by 2 is 6...

    Could someone help me?

    Thanks in advance!

    "since 12! is divisible by 2 ten times, by 3 five times, by 5 two times and by 7 and 11 only once.""

  • Loading more items...