Count Divisor

PHOTO EMBED

Sun May 01 2022 23:53:54 GMT+0000 (Coordinated Universal Time)

Saved by @GreenMark #javascript

//Count Divisors
// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
   main(stdin_input);
});

function main(input) {
    const data= input.toString().split("\n");
    
    console.log(divisors(data[0]));       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail



// Write your code here
// Sample code to perform I/O:
//Enter your code here

function divisors(s) {
    
    var arr = s.split(" ").map(item => Number(item));
    
    
    const l = arr[0];
    const r = arr[1];

    const k = arr[2];

    
    var count =0;

    for (var i=l; i<=r; i++) {
        if ((i % k)==0) count++
        
    }
    
    return count; 
    
}
     
content_copyCOPY

Problem You have been given 3 integers - l, r and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count. Input Format The first and only line of input contains 3 space separated integers l, r and k. Output Format Print the required answer on a single line. Constraints Sample Input 1 10 1 Sample Output 10

https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/count-divisors/