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 6843999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:19:20+00:00 2026-05-27T00:19:20+00:00

In a programming contest, a problem was: Count all solutions to the equation: x

  • 0

In a programming contest, a problem was:

Count all solutions to the equation: x + 4y + 4z = n. You will be
given n and you will determine the count of solutions. Assume x, y and z are positive integers.

I have considered using triple for loops (brute force), but it was unefficient, causing TIME LIMIT EXCEED. (since the n may be = 1000,000):

int sol = 0;
for (int i = 1; i <= n; i++)
{
 for (int j = 1; j <= n / 4; j++)
 {
  for (int k = 1; k <= n / 4; k++)
   {
      if (i + 4 * j + 4 * k == n)
         sol++;
   }
 }
}

My friend could solve the problem. When I asked him, he said that he didn’t use brute force at all. Instead, he converted the equation to a ‘series’ (i.e. summition). I asked him to tell how me but he refused 🙂

Can I know how?

  • 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-27T00:19:21+00:00Added an answer on May 27, 2026 at 12:19 am

    This is particular case of coin change problem, which is solved in general by dynamic programming.

    But here we can elaborate simple solution. I consider x,y,z > 0

    x + 4*(y+z)=n
    Let y + z = q = p + 1 (q > 1, p > 0)

    x+4*q=n

    x+4*p=n-4

    There are M = Floor((n-5)/4) variants for x and p, hence there are M possible values of
    q = 2..M+1
    For every q>1 there are (q-1) variants of y and z: q = 1 + (q-1) = 2 + (q-2) +..+(q-1)+1

    So we have N=1 + 2 + 3 + … + M = M * (M + 1)/2 solutions

    Example:

    n = 15;

    M = (15 – 5) div 4 = 2

    N = 3

    (3,1,2),(3,2,1),(7,1,1)

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

Sidebar

Related Questions

I have a problem programming with Android SDK 1.6. I'm doing the same things
I have a little problem in object programming in javascript There is a class
This is a problem appeared in today's Pacific NW Region Programming Contest during which
Problem Given two integers a, b, a < b. Display its decimal expansion. You
I'm very new to programming in Android, but have been struggling all day with
everyone. I'm programming with c# language and I have a problem with WebClient class.
In an online judge programming contest problem I am required to output up to
I have a problem: I am programming an app that is using a searchBar
I'm new to python programming. I have this problem: I have a list of
I am building programming contest software. A user's program is received by our judging

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.