Please Fill out the Feedback Form for Code Radius

Enormous Input Test : INTEST | CodeChef Solution

Problem

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.

Please Share this article...

Input Format

The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.

Output Format

Write a single integer to output, denoting how many integers ti are divisible by k.

Constraints

Sample

Input
7 3
1
51
966369
7
9
999996
11
Output
4

Explanation

The integers divisible by 33 are 51, 966369, 9,51,966369,9, and 999996999996. Thus, there are 44 integers in total.

Solution

#include <iostream>
using namespace std;

// Solution from : Code Radius [ https://radiuscode.blogspot.com/ ]

int main() {
 ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t % k == 0) {
			ans++;
		}		
	}
	cout << ans << "\n";
 return 0;
}
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader(inputStream);
		int n = in.nextInt();
		int k = in.nextInt();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			if (x % k == 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
				    tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
				    throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}
(n, k) = map(int, input().split(' '))
ans = 0
for i in range(n):
	x = int(input())
	if x % k == 0:
		ans += 1
print(ans)

Please First Try to Solve Problem by Yourself.

Post a Comment

© Code Radius. All rights reserved. Distributed by Code Rdius Distributed by Pro Templates