Tips for Completing Problems

Factors

A number's factors are all the positive integers that evenly divide the number, giving no remainder.

For example, the number 24 has 8 factors: 1, 2, 3, 4, 6, 8, 12, 24.

To find out if a number is a factor of another number, then you should check the remainder after division. Most programming languages provide an operator mod which gives the remainder after division. In C, C++ and Java this operator is %. So, for example, 10%3 gives 1 as 1 is the remainder after division of 10 by 3. If the remainder after division is zero, then the divisor is a factor of the dividend. In other words, there is an even division. For example 10%2 gives 0 therefore, 2 is a factor of 10.

Close Close this window

Leap Years

A leap year occurs when the year is divisible by 4, but not divisible by 100, except when it is divisible by 400. For example:

In a leap year February has 29 days instead of the usual 28. Because of this, a leap year has 366 days instead of 365.

Close Close this window

Prime Numbers

A prime number is a number which has no factors apart from itself and one. For example, the number 7 is prime as it has no factors apart from 7 and 1. The number 6 is not prime as it has divisors 6, 3, 2 and 1.

The number 1 is not considered a prime number.

Close Close this window

File Redirection

Using file redirection allows you to reuse a list of inputs by typing them in a file, then using the file instead of the keyboard as input.

A program started from the command prompt can be told to take it's input from a text file. Normally, to start a program you type the name of your program then hit enter. With file redirection you type the name of the program, a less than symbol < then the name of the text file...

solution.exe < input.txt

When using file redirection none of the input data will be displayed on your screen (it is being sent to the program), only the output data will appear.

In DOS, to copy output from the command prompt, right-click on title bar of the window, select Edit then Mark, highlight the output and hit enter. It will be copied to the clipboard.

In Linux, to copy output from the terminal, highlight the output and use the menu in your terminal to copy it to the clipboard.

Close Close this window

Integer Division

It is often useful to distinguish between arithmatic operations on floating point numbers (eg. 1.23) and oeprations on integers (eg. 1).

With integer arithmetic an operation on two integers should have an integer result. For addition, subtraction and multiplication, this is as you would expect. For division this gives a different result to floating point operation.

When performing integer division any fractional component of the result is dropped. For example 7/2 is not 3.5, it is just 3. The result is not rounded, it is truncated (any digits after the decimal place are cut off) for example 5/3 is 1.

Some languages apply these rules if both operands are integers, but in some languages you may have to enforce this form of operation.

Close Close this window

The Mod Operator

The Mod operator (usually represented as a % symbol) finds the remainder after integer division.

For example there are two whole groups of 3 in 7 with 1 left over, this is the remainder, so 7%3 results in 1.

The mod operator is a binary operator (taking two operands) like +, - and *.

Close Close this window