Thread: My homework c project (help)

  1. #31
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,791
    Quote Originally Posted by john.c View Post
    I vote to not explain it to him. If he can't figure it out from what's been given so far then that's too bad.
    I agree that there's is surely enough written here to see the pattern now. I do wonder what the homework is for (school?/uni?/subject?) though because it's not really about programming at the end of the day (Edit: that was a stupid thing for me to say; of course it's programming because problem solving is what programming is). After replacing my prime sieve with trial division (there's so few primes involved I dunno why I bothered with a sieve in the first place) my entire program is 20 lines long :/
    Last edited by Hodor; 12-12-2019 at 05:30 PM.

  2. #32
    Registered User
    Join Date
    Dec 2019
    Posts
    17

    Unhappy

    Quote Originally Posted by john.c View Post
    I vote to not explain it to him. If he can't figure it out from what's been given so far then that's too bad.
    I solved the problem by own way but it is very slow. How can i get to the conclusion faster? it takes about 4 hours. At least answer this.

    MY CODE:
    insert
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    unsigned long long int gcd(unsigned long long int n, unsigned long long int b);
    
    
    int main()
    {
        
        unsigned long long int n, b = 13, gn = 0;
    
    
        printf("Enter n:");
        scanf_s("%llu", &n);
        
        if (n < 4)
        {
            printf("\nERROR!!\n");
        }
        else if (n == 4)
            printf("\n g(%llu): 13\n", n);
    
    
        else if (n == 5)
            
        gn = b + gcd(n, b);
    
    
        else  
            for (unsigned long long int i = 5; i < n; i++)
            {
                b = b + gcd(i, b);
                gn = b + gcd(i+1, b);
            }
        
        printf("\n%llu\n", gn);
        
        printf("\n\n");
        system("pause");
    }
    unsigned long long int gcd(unsigned long long int n, unsigned long long int b)
    {
        if (b == 0)
            return n;
        else
            return gcd(b, n % b);
    }

  3. #33
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,791
    @muhammetekurt I can take you through it, but you'd probably be better reading the discussion forum regarding the problem on Project Euler because you can then see different perspectives and even formal proofs.

    Edit: vbulletin keeps parsing my URLs even when I click do not automatically parse urls :/ If the two links below don't work, the second is (without the https prefix) projecteuler.net/thread=443

    Edit 2: Is this really homework? If so, homework for what? Also, did you graph the output (of the test values on the first page of this thread) as suggested?

    a) sign up for Project Euler, put in your answer for problem 443: Problem 443 - Project Euler
    b) after it says yay you got it right, visit the discussion forum (after you solve the problem you can get the link to the discussion thread from the problem page): Sign In - Project Euler
    Last edited by Hodor; 12-13-2019 at 05:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With C++ Console Homework Project
    By Sikkirigi in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2016, 10:54 AM
  2. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  3. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  4. This Is Not Homework/ A Project
    By joebenjamin in forum C Programming
    Replies: 2
    Last Post: 09-24-2007, 08:42 PM
  5. Homework project(need help)
    By kantze in forum C++ Programming
    Replies: 8
    Last Post: 12-15-2006, 10:41 AM

Tags for this Thread