Skip to content

Instantly share code, notes, and snippets.

@Krymancer
Last active June 25, 2019 15:47
Show Gist options
  • Save Krymancer/35377d977b4a3476359026749e54018a to your computer and use it in GitHub Desktop.
Save Krymancer/35377d977b4a3476359026749e54018a to your computer and use it in GitHub Desktop.
Fast I/O methods for competitive programming
#include <bits/stdc++.h>
using namespace std;
int main(){
// THIS TWO LINES
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//EXAMPLE
int n, k, t;
int cnt = 0;
cin >> n >> k;
for(int i=0; i<n; i++){
cin >> t;
if(t % k == 0) cnt++;
}
cout << cnt << "\n";
return 0;
}
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out), true);
int cnt = 0;
int n = sc.nextInt();
int k = sc.nextInt();
int t;
for(int i=0; i<n; i++){
t = sc.nextInt();
if(t % k == 0) cnt++;
}
out.println(cnt);
/*
Other types of input
int n = sc.nextInt(); // read input as integer
long k = sc.nextLong(); // read input as long
double d = sc.nextDouble(); // read input as double
String str = sc.next(); // read input as String
String s = sc.nextLine(); // read whole line as String
int result = 3*n;
out.println(result); // print via PrintWriter
*/
out.close();
}
//PrintWriter for faster output
public static PrintWriter out;
//Class for faster input
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
def main():
from sys import stdin, stdout
n, k = stdin.readline().split()
n = int(n)
k = int(k)
cnt = 0
lines = stdin.readlines()
for line in lines:
if int(line) % k == 0:
cnt += 1
stdout.write(str(cnt))
if __name__ == "__main__":
main()
@Krymancer
Copy link
Author

I rename the c++ and python files only czMain.java has getting the gist name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment