Coprime Range CodeChef Solution

Problem -Coprime Range CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Coprime Range CodeChef Solution in C++17


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mpa 				make_pair
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;	
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}


void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void file_i_o()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

int modularExponentiation(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
int prime[1000006]={0};
void primes()
{
	loop(i,0,1000005)
	{
		prime[i]=0;
	}
	prime[1]=1;
	prime[0]=1;
	for(int i=2;i*i<=1000005;i++)
	{
		if(prime[i]==0)
		{
			for(int j=i*i;j<=1000005;j+=i)
			{
				prime[j]=1;
			}
		}
	}
}
int main(int argc, char const *argv[]) {
	file_i_o();
	int t;
	cin>>t;
	primes();
	while(t--)
	{
		int l,r;
		cin>>l>>r;
		int ans;
		for(int i=r+1;;i++)
		{
			if(prime[i]==0)
			{
				ans=i;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Coprime Range CodeChef Solution in C++14


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define Time cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#define pb push_back
#define mp make_pair
#define line cout << endl;
#define ff first
#define ss second
#define vi vector<int>
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;
#define printv(v)                      \
  for (int i = 0; i < (v.size()); i++) \
  {                                    \
    cout << v[i] << " ";               \
  }                                    \
  line;
#define onesbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define sp(x, y) fixed << setprecision(y) << x
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)
#define tk(x) \
  int x;      \
  cin >> x;
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
#define debug(x)     \
  cerr << #x << " "; \
  _print(x);         \
  cerr << endl;
#else
#define debug(x)
#endif
template <class T>
void _print(T t)
{
  cerr << t;
}

template <class T, class V>
void _print(pair<T, V> p)
{
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  cerr << "}";
}

template <class T>
void _print(vector<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(vector<vector<T>> v)
{
  cerr << "[\n";
  for (int l = 0; l < v.size(); l++)
  {
    {
      for (int k = 0; k < v[l].size(); k++)
        cerr << v[l][k] << " ";
    }
    cerr << "\n";
  }
  cerr << "]";
}

template <class T, class V>
void _print(map<T, V> v)
{
  cerr << "[ ";
  for (auto i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

template <class T>
void _print(set<T> v)
{
  cerr << "[ ";
  for (T i : v)
  {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}

const long long inf = 1e18;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

bool isValid(string s)
{
  int len = s.size();
  for (int i = 0; i < len / 2; i++)
  {
    if (s[i] != s[len - 1 - i])
      return false;
  }
  return true;
}

void rotateMatrix(vector<vector<int>> &v, int n)
{
  for (int i = 0; i < n / 2; i++)
  {
    for (int j = i; j < n - i - 1; j++)
    {
      int ptr = v[i][j];
      v[i][j] = v[n - 1 - j][i];
      v[n - 1 - j][i] = v[n - 1 - i][n - 1 - j];
      v[n - 1 - i][n - 1 - j] = v[j][n - 1 - i];
      v[j][n - 1 - i] = ptr;
    }
  }
}

vector<bool> is_prime(10001, 1);
vector<int> primes;

void seive()
{
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i < 10001; i++)
  {
    if (is_prime[i])
    {
      primes.push_back(i);
      for (int j = i + i; j < 10001; j += i)
      {
        is_prime[j] = 0;
      }
    }
  }
}

bool ispal(int ind,int ind2,string s,int dp[],int n){
    while(ind2>=ind){
        if(s[ind]==s[ind2]){
            ind++;ind2--;
        }
        else
            return 0;
    }
    return 1;
}

int rec(int ind,string s,int dp[],int n) {
    if(ind==n)
      return 1;
    if(dp[ind]!=-1)
       return dp[ind];
    int ans=0;
    for(int i=ind;i<n;i++){
        if(ispal(ind,i,s,dp,n)){
            ans=(ans+rec(i+1,s,dp,n))%1000000007;
        }
    }
    return dp[ind]=ans;
}



int32_t main() {

  ll t; cin >> t;
  // seive();
  while (t--) {

    ll l,r;cin>>l>>r;

 
    cout<< 1002583<<endl;
   

    
    
    

    
    
      
  }
  return 0;
}

Coprime Range CodeChef Solution in PYTH 3


# cook your dish here
from sys import stdin, stdout

for _ in range(int(stdin.readline())):
    L, R = map(int, stdin.readline().split())
    stdout.write('{}\n'.format(1000003))

Coprime Range CodeChef Solution in C

#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int i,k;
        scanf("%d%d",&i,&k);
        printf("1299827\n");
    }
}

Coprime Range CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            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;
        }
    }
    static boolean prime[]= new boolean[10000001];
    public static void  sieve()
    {
        
        for(int i=0;i<=10000000;i++)
            prime[i] = true;
        prime[0] = prime[1] = false;
        for(int p = 2; p*p <=10000000; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == true)
            {
                // Update all multiples of p
                for(int i = p*p; i <= 10000000; i += p)
                    prime[i] = false;
            }
        }
        
    }
     static ArrayList<Integer> primeFactors(int n)
    {
        ArrayList<Integer> pflist=new ArrayList<>();
        int c = 2;
        while (n > 1) {
            if (n % c == 0) {
                pflist.add(c);
                n /= c;
            }
            else
                c++;
        }
        return pflist;
    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastReader sc = new FastReader();
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int cases = sc.nextInt();
        //sieve();
        while(cases-->0)
        {
            int x=sc.nextInt();
            int y=sc.nextInt();
            out.write(1000003+"\n");
        }
        out.flush();
	}
	public static void reverse(int[] array)
	{
	    int n=array.length;
	    for(int i=0;i<n/2;i++)
	    {
	        int temp=array[i];
	        array[i]=array[n-i-1];
	        array[n-i-1]=temp;
	    }
	}
	public static String dectobin32(int x)
    {
        StringBuilder result = new StringBuilder();
 
        for (int i = 31; i >= 0 ; i--)
        {
            int mask = 1 << i;
            result.append((x & mask) != 0 ? 1 : 0);
        }
        //Integer.parseInt(result,2)
        return result.toString();
    }

}
class Pair implements Comparable<Pair> {
    int first,second;
    
    public Pair(int first,int second)
    {
        this.first =first;
        this.second=second;
    }
    public int compareTo(Pair b)
    {
        //first element in descending order
         if (this.first!=b.first)
            return (this.first>b.first)?-1:1;
        else 
            return this.second<b.second?-1:1;
            //second element in incresing order
    }
}

Coprime Range CodeChef Solution in PYPY 3

for _ in range(int(input())):
    l,r = map(int,input().split())
    print(1000003)

Coprime Range CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	st = raw_input().split()
	L = int(st[0])
	R = int(st[1])
	P = 1000003
	print P
# endfor i

Coprime Range CodeChef Solution in C#

using System;
using System.Collections.Generic;

public class Test
{
    	private static void Fill(IList<long> list, ref string str)
		{
			checked
	        {
		        list.Clear();
		        var strIdx = 0;
		        var sign = 1;
		        var curr = 0;

		        while (strIdx < str.Length)
		        {
			        if (str[strIdx] == ' ')
			        {
				        list.Add(sign * curr);
				        curr = 0;
				        sign = 1;
			        }
			        else if (str[strIdx] == '-')
			        {
				        sign = -1;
				        curr = 0;
			        }
			        else
			        {
				        curr *= 10;
				        curr += str[strIdx] - '0';
			        }

			        strIdx++;
		        }

		        list.Add(sign * curr);
	        }
        }

        private interface IInputReader
        {
	        string ReadInput();
        }

        private class ConsoleReader : IInputReader
        {
	        public string ReadInput() => Console.ReadLine().Trim();
        }
    
	public static void Main()
	{
		 checked
	        {
		        var reader = new ConsoleReader();
		        var tests = int.Parse(reader.ReadInput());
				List<long> lr = new List<long>(2);

				for (int i = 0; i < tests; i++)
		        {
			        var str = reader.ReadInput();
					Fill(lr, ref str);
					Console.WriteLine(1000000007);
		        }
	        }
	}
}

Coprime Range CodeChef Solution in GO

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		l, r := readTwoNums(reader)
		res := solve(l, r)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(l, r int) int {
	return 1000000007
}
Coprime Range CodeChef Solution Review:

In our experience, we suggest you solve this Coprime Range CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Coprime Range CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Coprime Range CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *