• Welcome to Programming_info!!

    Here you will get questions as well as there solutions.
    we provid you daily with a new question and it's solution.
    we have codechef and hackerrank solution for beginner now.

  • Welcome to Programming_info!!

    Here you will get questions as well as there solutions.
    we provid you daily with a new question and it's solution.
    we have codechef and hackerrank solution for beginner now.

  • Welcome to Programming_info!!

    Here you will get questions as well as there solutions.
    we provid you daily with a new question and it's solution.
    we have codechef and hackerrank solution for beginner now.

  • Welcome to Programming_info!!

    Here you will get questions as well as there solutions.
    we provid you daily with a new question and it's solution.
    we have codechef and hackerrank solution for beginner now.

  • Welcome to Programming_info!!

    Here you will get questions as well as there solutions.
    we provid you daily with a new question and it's solution.
    we have codechef and hackerrank solution for beginner now.

Enormous Input Test||codechef||beginner solution ||programming info

Enormous Input Test

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.

Input

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

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

Example

Input:
7 3
1
51
966369
7
9
999996
11

Output:
4
solution using c++:-
// Note that this problem is for testing fast input-output.
// We can use scanf, printf in C langauge, which are quite fast in general :)
#include <bits/stdc++.h> 

using namespace std;

// Usually, you can use scanf/printf in C++.
// However, if you want to use cin/cout, it is usually slow.
// To make it faster. Use cin.tie(NULL) and set ios_base::sync_with_stdio(false)
// See the below code for details.

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

// Read the input n, k
int n, k;
cin >> n >> k;

// ans denotes number of integers n divisible by k
int ans = 0;

for (int i = 0; i < n; i++) {
int t;
cin >> t;
if (t % k == 0) {
ans++;
}
}

// Print the ans.
cout << ans << "\n";
return 0;
}

alternate solution:-
#include <iostream> 
#include<cstdio>

using namespace std;
int main() {
// Read the input n, k
int n, k;
scanf("%d %d",&n,&k);
// ans denotes number of integers n divisible by k
int ans = 0;
for (int i = 0; i < n; i++) {
int t;
scanf("%d",&t);

if (t % k == 0) {
ans++;
}
}

// Print the ans.
printf("%d\n",ans);

return 0;
}


Share:

Turbo Sort||codechef||beginner solution ||programming info

Turbo Sort

Given the list of numbers, you are to sort them in non decreasing order.

Input

t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order.

Example

Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
Solution using C++ language:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
 // your code goes here
 int t,i;
 cin>>t;
 int a[t];
 for(i=0;i<t;i++)
 {
     cin>>a[i];
 }
 sort(a,a+t);
 for(i=0;i<t;i++)
 {
     cout<<a[i]<<endl;
 }
 return 0;
}

Share:

Small factorials||codechef||beginner solution ||programming info

Small factorials

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3
Sample output:
1
2
120
6
Solution using C++ language:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> 
using namespace boost::multiprecision; 
using namespace std;


int main() 
{
 int t;
 cin>>t;
 
 while(t--)
 {
     int n;
     cin>>n;
     cpp_int f=1;
     for(int i=1;i<=n;i++)
     {
            f=f*i;
     }         
     cout<<f<<endl;
 }
 return 0;
}
alternate solution:-
#include <iostream>
using namespace std;

int main() 
    {
     int t;
     cin>>t;
     while(t--)
         {
             int n;
             cin>>n;
             int size=1000,fact[size],extra=0,j=size-1;
             fact[size-1]=1;
                      while(n>1)
                          {
                         int x;
                             for(int k=size-1;k>=j;k--)
                                 {
                                     x=fact[k]*n+extra;
                                     fact[k]=x%10;
                                     extra=x/10;
                                 }
                             while(extra>0)
                                 {
                                     fact[--j]=extra%10;
                                     extra/=10;
                                 }
                             n--;
                         }
                     for(int k=j;k<size;k++)
                         {
                             cout<<fact[k];
                         }
                     cout<<endl;
            }
     return 0;
    }

Share:

Day 9: factorial 3|| hackerrank || 30 days of code || programming_info

Objective
Today, we're learning and practicing an algorithmic concept called Recursion. Check out the Tutorial tab for learning materials and an instructional video!
Recursive Method for Calculating Factorial
Task
Write a factorial function that takes a positive integer,  as a parameter and prints the result of  ( factorial).
Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of .
Input Format
A single integer,  (the argument to pass to factorial).
Constraints
  • Your submission must contain a recursive function named factorial.
Output Format
Print a single integer denoting .
Sample Input
3
Sample Output
6
Explanation
Consider the following steps:
From steps  and , we can say ; then when we apply the value from  to step , we get . Thus, we print  as our answer.
Solution using C language:
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* readline();

// Complete the factorial function below.
int factorial(int n) {
    if (n>=1)
        return n*factorial(n-1);
    else
        return 1;


}

int main()
{
    FILE* fptr = fopen(getenv("OUTPUT_PATH"), "w");

    char* n_endptr;
    char* n_str = readline();
    int n = strtol(n_str, &n_endptr, 10);

    if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); }

    int result = factorial(n);

    fprintf(fptr, "%d\n", result);

    fclose(fptr);

    return 0;
}

char* readline() {
    size_t alloc_length = 1024;
    size_t data_length = 0;
    char* data = malloc(alloc_length);

    while (true) {
        char* cursor = data + data_length;
        char* line = fgets(cursor, alloc_length - data_length, stdin);

        if (!line) { break; }

        data_length += strlen(cursor);

        if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; }

        size_t new_length = alloc_length << 1;
        data = realloc(data, new_length);

        if (!data) { break; }

        alloc_length = new_length;
    }

    if (data[data_length - 1] == '\n') {
        data[data_length - 1] = '\0';
    }

    data = realloc(data, data_length);

    return data;
}
Share:

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support