Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For n identical candies given to k distinct children, with zero candies allowed and no other limits, the number of distributions is C(n+k−1, k−1). You get that count without listing a single split. The formula changes when the rules change, though, so the real work is deciding which model the question describes before you choose a formula.

Settle the model before you count

Most wrong answers to candy-distribution questions come from using a formula for a neighbouring problem. Five questions define the model:

  • Are the candies identical? If they are, only the number each child receives matters. If they are individually distinguishable, the problem is a different one and stars and bars does not apply directly.
  • Are the children distinct? Named or ordered recipients make (2, 5, 3) and (5, 2, 3) different outcomes. Interchangeable recipients require a different count.
  • Can a child receive nothing? Zero-allowed and at-least-one versions use different formulas.
  • Are there minimums or maximums? Each one changes the calculation in its own way.
  • Must every candy be handed out? The formulas below assume that all n candies are distributed.

Once these are fixed, write the problem as an equation. Let x1, x2, …, xk be the number of candies each child receives. The question becomes: how many nonnegative integer solutions does x1 + x2 + … + xk = n have, under the stated limits?

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Formulas for each version of the question

The table below gives the standard cases, with the worked values from the teaching sources used to check them.

#1 Best Overall
Holiday Assorted Chocolate Truffle Gift Box - 15 Count. Ideal Assorted Chocolate Gift Box for Easter, Anniversary, Birthday and Special Occasions, Perfect for Sharing with Loved Ones
  • Premium Assorted Mothers Day Truffles: The Tammze assorted chocolate gift box is thoughtfully crafted to deliver a luxurious experience. Each truffle is carefully made with smooth chocolate shells and creamy centers, then arranged in a beautiful box that enhances enjoyment. This truffle chocolate assortment is ideal for those who appreciate fine flavors, elegant packaging and a refined tasting experience.
  • Sophisticated Gift Choice: This chocolates gift box is designed to leave a lasting impression, making it an excellent choice for anniversaries, holidays, thank you gifts and special celebrations. Its premium look and carefully balanced assortment create a memorable gifting experience that feels thoughtful and indulgent, whether given to friends, family members, coworkers or business partners.
  • Chocolate Box for Sharing: This easter chocolate box offers a refined alternative to traditional candy, making it perfect for expressing love, appreciation and affection. The smooth, indulgent chocolate truffles are ideal for sharing during easter celebrations or intimate moments, creating an experience that feels personal and thoughtfully chosen for someone special.
  • Detailed Flavor Assortment: Inside this chocolate box you’ll find a carefully balanced variety of flavors including Milk Chocolate Covered Caramel Cream, Caramelized White Chocolate Covered Hazelnut Cream with cocoa, Milk Chocolate Covered Cocoa Cream, Milk Chocolate Covered Strawberry Flavored Cream and Coconut & White Chocolate Covered Coconut Cream. Each piece delivers a distinct taste profile.
  • 15 Piece Gourmet Assortment: This 15 piece easter chocolates selection is thoughtfully portioned to offer variety without overwhelming, making it perfect for sharing. The combination of elegant presentation and careful craftsmanship makes this fancy chocolate assortment suitable for both special occasions and everyday indulgence, delivering consistent quality and enjoyment in every box.
Version of the question Count Worked value (n, k) Source of the worked value
Identical candies, distinct children, zero allowed, no caps C(n+k−1, k−1) 10 candies, 4 children: C(13,3) = 286 CIT 5920 combinatorics course notes (Fall 2025)
Identical candies, distinct children, zero allowed, no caps C(n+k−1, k−1) 10 candies, 3 children: C(12,2) = 66 Xiaohui Xie, Stars & Bars notes (© 2025)
Identical candies, distinct children, every child gets at least one C(n−1, k−1), for n ≥ k 10 candies, 3 children: C(9,2) = 36 Xiaohui Xie, Stars & Bars notes (© 2025)
Identical candies, with minimums a1 … ak C(n − Σai + k − 1, k − 1), if n − Σai ≥ 0 Not stated in the sources; a worked example is given below Shift method described in CIT 5920 combinatorics course notes (Fall 2025)
Identical candies, with upper caps on each child Inclusion–exclusion on the unrestricted count Ordered triples summing to 15 with caps 5, 6, 7: 10 Xiaohui Xie, Stars & Bars notes (© 2025)

Zero allowed: the basic case

When children may receive nothing and there are no other constraints, each solution of x1 + … + xk = n is one allocation. Stars and bars counts all of them at once with C(n+k−1, k−1). For 10 candies and 4 children, that is C(13,3) = 286. Note that the value 286 is correct for this setup only; a different number of children or a different rule gives a different count.

Every child gets at least one candy

Hand each child one candy first. That uses k candies and leaves n − k candies to distribute freely, with zero now allowed again. The count is C(n−1, k−1), valid when n ≥ k. For 10 candies and 3 children the result is C(9,2) = 36. The positive case is easy to confuse with the zero-allowed case, which gives 66 for the same numbers. The wording of the question decides which applies.

Rank #2
Bucket of Candy Variety Pack - 4LB Assorted Box - Gift for Kids, College Students & Adults (4 Pound)
  • 🍬UNWRAP TIMELESS JOY - Dive into a world of sweetness with our Sweetside Original Mix Assorted Candies Bucket. This candy bulk haven is a celebration of classic flavors that have delighted generations. From iconic brands like Welch's, Black Forest, and Skittles, indulge in an array of favorites that cater to every palate.
  • 🍭FLAVORFUL VARIETY, ENDLESS FUN - Elevate your candy game with this bulk candy bucket mix. Individually wrapped, these candies are ready to make any occasion memorable. Whether it's a party, event, or just a spontaneous get-together, this assortment promises to add an element of sweetness to every moment.
  • 🍡DELIGHTFULLY FAMILIAR TREATS - Embrace the heartwarming familiarity of classic candy favorites. The Sweetside Original Mix brings together timeless choices like Laffy Taffy, Sour Patch, and Swedish Fish. With each unwrapping, you're inviting a rush of nostalgia and joy.
  • 😍PERFECT FOR YOUNG HEARTS - From kids to the young at heart, this variety candy basket treat collection is designed to delight everyone. Whether you're creating party favors, filling candy jars, or surprising a loved one, these candies are your ultimate allies in creating smiles and unforgettable moments.
  • 🤤SWEETNESS IN EVERY OCCASION - Elevate celebrations, events, and everyday moments with Sweetside's Original Mix. These assorted candies represent more than just treats; they're happiness in a wrapper. Let the irresistible allure of classic flavors make your gatherings and special occasions even more memorable.

Different minimums for each child

If child i must receive at least ai candies, substitute xi = ai + yi, where each yi is nonnegative. The yi sum to n − Σai. If that remainder is negative, there are no valid distributions. If it is zero or positive, apply the basic formula to the remainder, using k variables.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Worked illustration, computed for this article: 10 candies, child A must get at least 2, child B at least 3, child C has no minimum. The remainder is 10 − 5 = 5, so the count is C(5+3−1, 3−1) = C(7,2) = 21.

Rank #3
Ferrero Collection Assorted Chocolate Candy Gift Box, 48 Ct, 18.2 oz
  • GOURMET CHOCOLATE GIFT BOX: This 48-count Ferrero Collection gift box features an assortment of individually wrapped Ferrero Rocher, Confetteria Raffaello, and Rondnoir confections
  • ASSORTED TREATS: Enjoy three delicious flavors, Ferrero Rocher with hazelnut milk chocolate; lusciously layered Confetteria Raffaello with white almond, cream and coconut; and rich dark chocolate Rondnoir
  • PREMIUM CONFECTIONS: Expertly crafted with premium ingredients, this Ferrero Collection delivers decadent flavor and texture one exquisite bite at a time
  • RAISE A ROCHER: Create sweet moments with Ferrero Collection, indulgent treats perfect for sharing with family, friends, or savoring for yourself
  • HOLIDAY-READY GIFTING: Perfect for Valentine’s Day, Easter, or a Mother’s Day gift, this holiday gift adds elegance to every celebration

Maximum caps on each child

An upper bound cannot be handled by the unrestricted formula alone, because that formula also counts allocations that break the cap. Use inclusion–exclusion instead. The violation for a variable with cap m is xi ≥ m+1. Shift that variable by m+1 and count the solutions in which the violation occurs. With different caps, each variable uses its own threshold. Then subtract the single-variable violations, add back the pairwise overlaps, subtract the triple overlaps, and so on.

Checking a capped count step by step

The Xie notes count ordered triples (a, b, c) with a + b + c = 15, where a ≤ 5, b ≤ 6, and c ≤ 7. The steps below reproduce that count, which is a useful test for the method.

Rank #4
Gift A Snack - Snack Box Variety Pack Care Package (40 Count) Greeting Card
  • AMERICA'S FAVORITE SNACKS AND CANDIES: The "Gift A Snack" Snack Variety Pack contains a delicious assortment of snacks and candies, including chewy, crunchy, and sweet treats that everyone loves, and much more
  • BEAUTIFULLY BRANDED HIGH-END PACKAGING: "Gift A Snack" beautifully designed mailer gift box will definitely impress your gift recipients even before they get their hands on the mouthwatering treats that are inside
  • CONVENIENT PACKAGING + GREETING CARD INCLUDED: Our snacks and candies are packed in individual servings, so that it's easier for you to grab while on the go. As if this were not enough, it also comes with a heartwarming greeting card
  • SPREAD THE JOY WITH THE PERFECT GIFT: "Gift A Snack"'s Variety Pack is filled with America's favorite snacks and candies and is the perfect gift for adults, teens, college students, and any loved one who you'd like to spread the joy to
  • HONESTY IS OUR MAIN VALUE: Due to supply chain issues, it's possible that some of the snacks in this box might have to be replaced for other snacks of similar or more value. (Hey, and don't forget to sign your name at check out so your recipient knows who the gift is from)
  1. Unrestricted total: C(15+3−1, 2) = C(17,2) = 136.
  2. Single violations: a ≥ 6 leaves a sum of 9, giving C(11,2) = 55. b ≥ 7 leaves 8, giving C(10,2) = 45. c ≥ 8 leaves 7, giving C(9,2) = 36. Subtract 55 + 45 + 36 = 136.
  3. Pairwise overlaps: a ≥ 6 and b ≥ 7 leaves 2, giving C(4,2) = 6. a ≥ 6 and c ≥ 8 leaves 1, giving C(3,2) = 3. b ≥ 7 and c ≥ 8 leaves 0, giving C(2,2) = 1. Add 6 + 3 + 1 = 10.
  4. Triple overlap: 6 + 7 + 8 = 21 exceeds 15, so it contributes 0.
  5. Result: 136 − 136 + 10 = 10.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why stars and bars works

Draw n stars, one for each identical candy. Place k − 1 bars between them to mark the boundaries between the k children. A child’s share is the number of stars between consecutive bars. An empty share appears as two adjacent bars, or as a bar at either end. Each arrangement of stars and bars corresponds to exactly one allocation vector (x1, …, xk), and each allocation produces exactly one arrangement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The arrangement has n + k − 1 positions in total. Choosing which k − 1 of them hold bars gives C(n+k−1, k−1). The count comes from this one-to-one correspondence, not from listing allocations. Richard Hammack’s Book of Proof states the same idea: “Thus we can describe any non-negative integer solution to the equation as a list of length 20+3 = 23 that has 20 stars and 3 bars.” The copy consulted for this article carries no publication date.

Best Value
The Snack Bar - Snack Care Package (40 count) - Variety Assortment with American Candy, Fruit Snacks, Gift Snack Box for Lunches, Office, College Students, Road Trips, Holiday Gifts
  • Snack Care Package, 40 count.
  • THE SNACK BAR BOX CONTAINS: A variety of snacks and bars to satisfy any type of craving.
  • PERFECT FOR: College, office meetings, hospitals, military, staff rooms, trips.
  • VARIETY ASSORTMENT: American Candy, Snacks and cookies.
  • SNACK BOX FOR: Lunches, Office, College Students, Road Trips, Holidays, Gifts or Yourself.

Common mistakes and how to avoid them

  • Using C(n+k−1, k−1) when every child must get one. Check the wording for “at least one” or “each gets something.” Switch to C(n−1, k−1).
  • Forgetting to shift minimums. Subtract the required minimums from n first, then count the remainder.
  • Applying an unrestricted formula to a capped problem. Use inclusion–exclusion so that over-cap allocations are removed.
  • Treating a textbook total as the answer to a different question. The values 286, 66, 36, and 10 answer only the exact setups described above.
  • Assuming candies are distinguishable. If each candy is unique, each child’s share can be arranged in many ways, so a different method is needed.

Practical checklist

  • Confirm that the candies are identical and the children are distinct.
  • Decide whether zero is allowed; use C(n+k−1, k−1) if it is, and C(n−1, k−1) if it is not.
  • Subtract any minimums from n, and stop if the result is negative.
  • For caps, count the unrestricted total and correct it with inclusion–exclusion.
  • Check your method on a small case, such as 10 candies and 3 children, before trusting it on a larger one.

The formulas in this article are standard results for identical objects placed into distinct groups. For a particular question, the candy total, the number of children, and the meaning of “valid” all come from the wording of that question. Teaching sources such as the CIT 5920 combinatorics course notes (Fall 2025) and Xiaohui Xie’s Stars & Bars notes (© 2025) use the same method for the examples cited above.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.