Alyona and Numbers


After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.

Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.

As usual, Alyona has some troubles and asks you to help.

InputThe only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).

OutputPrint the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.

Input
6 12
Output
14

Program:

import java.util.Scanner;
public class PairlsOfIntegers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter n, m : ");
int n = sc.nextInt();
int m = sc.nextInt();

int count = 0;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
if( (i+j)%5 == 0 )
count ++;
}
}
System.out.print(count);
}
}

Output 1 :
Enter n, m : 6   12
14

Output 2 :
Enter n, m : 11     14
31

Output 3 :
Enter n, m : 1   5
1

No comments:

Post a Comment