TopcoderArchive
Archive
Algorithm problem

FlatCatsBreeding

Problem statement, definition, constraints, and public examples.

Problem Statement

A flat cat is a fictional Martian animal known for being an extremely affectionate pet and also for being able to replicate itself promptly given favorable conditions. The cat replicates itself when it is D, 2*D, 3*D, ... days old, and each time, it creates K new kittens. You have been presented with a newborn flat cat. Return the number of days after which you will have at least T cats, assuming that cats don't die.

Definition

Class:
FlatCatsBreeding
Method:
days
Parameters:
int, int, int
Returns:
int
Method signature:
int days(int D, int K, int T)
(be sure your method is public)

Constraints

  • D will be between 1 and 100, inclusive.
  • K will be between 1 and 10, inclusive.
  • T will be between 1 and 1000000, inclusive.

Examples

  1. 4
    3
    1
    Returns: 0
    You have one cat as soon as you are presented with it, so you don't have to wait until it replicates.
  2. 4
    3
    4
    Returns: 4
    After 4 days, the first cat produces 3 kittens, so you will have a total of 4 cats.
  3. 4
    3
    9
    Returns: 8
    After 4 days, you'll have four cats. After 4 more days, each of those cats will produce 3 kittens, for a total of 16 cats. Note that you don't need to have exactly T cats, but at least T.
  4. 4
    3
    1000000
    Returns: 40
  5. 91
    6
    10433
    Returns: 455
  6. 9
    7
    17079
    Returns: 45
Back to all problems