Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:06:09+00:00 2026-05-28T18:06:09+00:00

Overall Problem: Project Euler 12 – What is the value of the first triangle

  • 0

Overall Problem: Project Euler 12 – What is the value of the first triangle number to have over five hundred divisors?

Focus of problem: The divisor function

Language: Python

Description: The function I used is brute and the time it take for the program to find a number with more divisors than x increases almost exponentially with each 10 or 20 numbers highers. I need to get to 500 or more divisors. I’ve identified that the divisor function is what is hogging down the program. The research I did lead me to divisor functions and specifically the divisor function which is supposed to be a function that will count all the divisors of any integer. Every page I’ve looked at seems to be directed toward mathematics majors and I only have high-school maths. Although I did come across some page that mentioned allot about primes and the Sieve of Atkins but I could not make the connection between primes and finding all the divisors of any integer nor find anything on the net about it.

Main Question: Could someone explain how to code the divisor function or even provide a sample? Maths concepts make more sense to me when I look at them with code. So much appreciated.

brute force divisor function:

def countdiv(a):
    count = 0
    for i in range(1,(a/2)+1):
        if a % i == 0:
            count += 1
    return count + 1    # +1 to account for number itself as a divisor
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:06:11+00:00Added an answer on May 28, 2026 at 6:06 pm

    If you need a bruteforce function to calculate Number of Divisors (also known as tau(n))

    Here’s what it looks like

    def tau(n):
            sqroot,t = int(n**0.5),0
            for factor in range(1,sqroot+1):
                    if n % factor == 0:
                            t += 2 # both factor and N/factor
            if sqroot*sqroot == n: t = t - 1 # if sqroot is a factor then we counted it twice, so subtract 1
            return t
    

    The second method involves a decomposing n into its prime factors (and its exponents).

    tau(n) = (e1+1)(e2+1)....(em+1) where n = p1^e1 * p2^e2 .... pm^em and p1,p2..pm are primes

    More info here

    The third method and much more simpler to understand is simply using a Sieve to calculate tau.

    def sieve(N):
            t = [0]*(N+1)
            for factor in range(1,N+1):
                    for multiple in range(factor,N+1,factor):
                            t[multiple]+=1
            return t[1:]
    

    Here’s it in action at ideone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So the overall problem is this: We have multiple property files <property file=prop1/> <property
I built my first site with jQuery and overall it turned out quite well
I have a large project in C# (.NET 2.0) which contains very large chunks
I have a site which has a number (20 or so) web parts. Each
Every time I have to estimate time for a project (or review someone else's
I have few own APIs with around 2000 classes overall. Some of them use
I have been working on a project and trying to find the source of
I have configured a Maven build for a very small GWT project I'm having.
On C# winforms project, I have a small table, a filter box, an Add
I have a kernel project with C files, C libraries and C++ libraries as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.