Several configuration procedures required to use Cocostudio to migrate to Android phones in the program

Source: Internet
Author: User
Tags fread

The subject is testing the speed at which the data is read.


If there is a lot of data to read, using CIN is very slow.

So it's a lot quicker to use scanf, but it's not fast enough if the amount of data is bigger.

So use fread here.

Start with a buffer and then read the data very quickly using fread chunks.


The topics are as follows:

Input

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

Output

Write a single integer to output, denoting how many integers ti is divisible by K.

Example
Input:7 31519663697999999611Output:4
Original title Address:

http://www.codechef.com/problems/INTEST/


#include <stdio.h>namespace{#define SIZE 65536}int enormousinputtest () {char buffer[size];unsigned n, K, c;scanf ( "%u%u\n", &n, &k); unsigned ans = 0;int num = 0;while ((c = fread (buffer, 1, SIZE, stdin)) > 0) {for (unsigned I = 0; I < C; i++) {if (buffer[i] = = ' \ n ') {if (num% k = = 0) ans++;num = 0;} Else{num = num * + buffer[i]-' 0 ';}} printf ("%u", ans); return 0;}

Testing this function is too fast.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.