TopcoderArchive
SRM29 Jun 2004
SRM 201

Multiples

Problem statement, definition, constraints, and public examples.

Problem Statement

You are to create a class Multiples with a method number, which takes three ints: min, max, and factor.

Given a range of integers from min to max (inclusive), determine how many numbers within that range are evenly divisible by factor.

Definition

Class:
Multiples
Method:
number
Parameters:
int, int, int
Returns:
int
Method signature:
int number(int min, int max, int factor)
(be sure your method is public)

Notes

  • If x is evenly divisble by y, there exists some integer k such that k * y = x.

Constraints

  • min will be between -1000000 and 1000000, inclusive.
  • max will be between -1000000 and 1000000, inclusive.
  • max will be greater than or equal to min.
  • factor will be between 1 and 1000, inclusive.

Examples

  1. 0
    14
    5
    Returns: 3
    The numbers 0, 5, and 10 are evenly divisible by 5, so this returns 3.
  2. 7
    24
    3
    Returns: 6
    The numbers 9, 12, 15, 18, 21, 24 are evenly divisible by 3, so this returns 6.
  3. -123456
    654321
    997
    Returns: 780
  4. -75312
    407891
    14
    Returns: 34515
Back to all problems