Sukarna_Paul's blog

By Sukarna_Paul, history, 6 weeks ago, In English,
 
 
 
 
  • Vote: I like it
  • +2
  • Vote: I do not like it

By Sukarna_Paul, history, 4 months ago, In English,

How can I approach for this problem ? https://codeforces.com/gym/102055/problem/L

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 4 months ago, In English,

How to avoid TLE for this problem as the number of test cases can be 10^4 .

Here is the problem link

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 5 months ago, In English,

Here is the problem link UVA Live 6844

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 5 months ago, In English,

I have been trying to solve this problem for last few days . Here is the Problem link SPOJ PTRI .

I have used Linear sieve , but the limit is so high that it is getting TLE in O(N) . I have tried it with sieve of aktin also. But still got TLE . Please help me to solve this one.

I found this problem in -Morass- blog Link . You can visit it , I am confident that you will find it useful.

Read more »

 
 
 
 
  • Vote: I like it
  • +11
  • Vote: I do not like it

By Sukarna_Paul, history, 5 months ago, In English,

I was solving the problem from SPOJ Link . But my solution is getting TLE. Please help me out!

Here is my solution :

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
using namespace std;

vector <ll> prime;
bitset <100000010> bs;

void sieve ()
{
	bs.set ();
    prime.pb(2LL);
	for (ll i = 3; i < 100000000; i+=2)
	{
		if (bs[i])
		{
			prime.pb(i);
			for (ll j = i * i; j < 10000000; j += i+i)
			{
				bs[j] = 0;
			}
		}
	}
}

int main(){
    IOS
    //freopen("output.txt","w",stdout);
    sieve();
    int i=0;
    unordered_map<int,int>r,c;

    for(auto it=prime.begin();it!=prime.end();){
        i++;
        for(int j=1;j<=i;j++){
            r[(*it)]=i;
            c[(*it)]=j;
            it++;
        }
    }
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int a;
        cin>>a;
        if(r[a]==0){
            cout<<"-1"<<endl;
            continue;
        }
        cout<<r[a]<<" "<<c[a]<<endl;

    }
}

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 5 months ago, In English,

How Can I Create A Contest On Codeforces?

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 5 months ago, In English,

This problem is from ACM ICPC Dhaka Regional 2018 (Contest Link)

How can I approach for this problem?

Problem Satement:

The function d(n) denotes the number of positive divisors of an integer n. For example d(24) = 8, because there are 8 divisors of 24 and they are 1, 2, 3, 4, 6, 8, 12 and 24. The function sndd(n) is a new function defined for this problem. This denotes “The summation of number of divisors of the divisors” of an integer n. For example,

sndd(24) = d(1) + d(2) + d(3) + d(4) + d(6) + d(8) + d(12) + d(24) = 1 + 2 + 2 + 3 + 4 + 4 + 6 + 8 = 30.

Given the value of n, you will have to find sndd(n!), here n! means factorial of n. So n! = 1 × 2 × 3 × … × n.

Input The input contains at most 1000 lines of test cases. Each line contains a single integer that denotes a value of n (1 ≤ n ≤ 10^6). Input is terminated by a line containing a single zero.

Output For each line of input produce one line of output. This line contains an integer that denotes the modulo 10000007 (or 10^7 + 7) value of sndd(n).

Sample Input 4 5 0

Sample Output 30 90

Read more »

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

By Sukarna_Paul, history, 6 months ago, In English,
 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 7 months ago, In English,

How can I approach for this Geometry problem . Here is the link URI 1291

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 7 months ago, In English,

How can I approach for this problem Problem Link

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By Sukarna_Paul, history, 8 months ago, In English,

How can I approach for this number theory problem ? [Problem Link](http:// https://codeforces.com/contest/1070/problem/A)

A. Find a Number time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output

You are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s.

Input The first line contains two positive integers d and s (1≤d≤500,1≤s≤5000) separated by space.

Output Print the required number or -1 if it doesn't exist.

Examples input 13 50 output 699998

input 61 2 output 1000000000000000000000000000001

input 15 50 output -1

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By Sukarna_Paul, history, 8 months ago, In English,

How can I approach for this problem ?

8085 Divisors (Link)

The number of divisor function or d(n) is a very interesting function in number theory. It denotes the number of positive divisors of a particular number. For example d(24) = 8 as 24 has eight divisors 1, 2, 3, 4, 6, 8, 12 and 24 . In mathematics factorial of a positive integer number n is written as n! and is defined as below: n! = 1 × 2 × 3 × · · · × n

Another interesting function AF(n) (Again factorial in short) is defined as: AF(n) = 1! × 2! × 3! × . . . × n!

Given n , your job is to find the value of d(AF(n)).

Input The input file contains at most 101 lines of inputs. Each line contains an integer n (0 < n < 5000001) . Input is terminated by a line containing a single zero. This value should not be processed.

Output For each line of input produce one line of output.

This line contains the modulo 100000007 (10^8 + 7) of d(AF(n)).

Sample Input 1 2 3 4 100 0

Sample Output 1 2 6 18 59417661

Read more »

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

By Sukarna_Paul, history, 11 months ago, In English,

Some Big integer problems for beginners Solving BigInteger Problem is fun. There are many problem solvers around the world who come to use Java BigInteger class though they do not code in Java usually. Here are some simple problems with their links and solution. This problem are chosen from different online judges. Try yourself before you see the solution.

Codeforces Gym : 112

Solution

import java.util.Scanner ;
import java.math.BigInteger;
public class Main{
  public static void main(String[] args){
    int a,b;
    Scanner input = new Scanner(System.in);
    a = input.nextInt();
    b = input.nextInt();
    BigInteger A = BigInteger.valueOf(a);
    BigInteger B= BigInteger.valueOf(b);
    System.out.printf("%d",A.pow(b).subtract(B.pow(a)));
    
  }
}

Uva 10183 — How Many Fibs?

Solution

import java.util.*;
import java.math.*;
public class Main{
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    BigInteger arr[] = new BigInteger[50000];
    arr[0]= BigInteger.valueOf(1);
    arr[1]= BigInteger.valueOf(2);
    for(int i=2;i<50000;i++){
      arr[i] = arr[i-1].add(arr[i-2]);
    }
    while(true){
      
      BigInteger a,b;
      a = input.nextBigInteger();
      b = input.nextBigInteger();
      if(b.compareTo(BigInteger.valueOf(0))==0){
        break;
      }
      int count=0;
      for(int i=0;i<50000;i++){
        if(arr[i].compareTo(a)>=0 && arr[i].compareTo(b)<=0){
          count++;
        }
        if(arr[i].compareTo(b)>0){
          break;
        }
      }
      System.out.println(count);
    }
  }
}

URI 1279

Solution

import java.util.*;
import java.math.*;
import java.io.*;  
public class Main{
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    boolean start = true;
    while(input.hasNext()){
      boolean leap_year = false;
      boolean ordinary = true;
      if(start == false){
        System.out.print("\n");
      }
      start = false;
      BigInteger year;
      year = input.nextBigInteger();
      BigInteger four;
      four = BigInteger.valueOf(4);
      BigInteger fourh;
      fourh = BigInteger.valueOf(400);
      BigInteger oneh;
      oneh = BigInteger.valueOf(100);
      BigInteger temp = year.remainder(four);
      if(temp.compareTo(BigInteger.valueOf(0))==0){
        temp = year.remainder(oneh);
        if(temp.compareTo(BigInteger.valueOf(0))==0){
          temp = year.remainder(fourh);
          if(temp.compareTo(BigInteger.valueOf(0))==0){
            System.out.println("This is leap year.");
            leap_year = true;
            ordinary = false;
          }
        }
        else{
          System.out.println("This is leap year.");
          leap_year = true;
          ordinary = false;
        }
      }
      temp = year.remainder(BigInteger.valueOf(15));
      if(temp.compareTo(BigInteger.valueOf(0))==0){
        System.out.println("This is huluculu festival year.");
        ordinary = false;
      }
      if(leap_year==true){
        temp = year.remainder(BigInteger.valueOf(55));
        if(temp.compareTo(BigInteger.valueOf(0))==0){
          System.out.println("This is bulukulu festival year.");
          ordinary = false;
        }
      }
      if(ordinary == true){
        System.out.println("This is an ordinary year.");
      }
    }
  }
}

Project Euler Problem 13

Solution

import java.util.*;
import java.math.*;

public class problem13{
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    BigInteger sum, a;
    sum = BigInteger.valueOf(0);
    for(int i=0;i<100;i++){
      a = input.nextBigInteger();
      sum = sum.add(a);
    }
    System.out.println(sum);    //take the first 10 digits manually
  }
}

Project Euler Problem 15

Solution

import java.math.*;

public class Problem15{
  public static void main(String[] args){
    BigInteger n=BigInteger.valueOf(1);
    BigInteger ans=BigInteger.valueOf(1);
    for(int i=0;i<40;i++){
        ans=ans.multiply(n);
        n= n.add(BigInteger.valueOf(1));
    }
    n=BigInteger.valueOf(1);
    BigInteger ans2=BigInteger.valueOf(1);
    for(int i=0;i<20;i++){
        ans2=ans2.multiply(n);
        n= n.add(BigInteger.valueOf(1));
    }
    System.out.println(ans.divide(ans2.multiply(ans2)));
  }
}

Project Euler Problem 16

Solution

import java.math.*;

public class Problem16{
  public static void main(String[] args){
    //BigInteger n=BigInteger.valueOf(1000);
    BigInteger two = BigInteger.valueOf(2);
    BigInteger ans = two.pow(1000);
    String s = ""+ans;
    System.out.println(s);
    int sum=0;
    for(int i=0;i<s.length();i++){
      sum+=s.charAt(i)-'0';
    }
    System.out.println(sum);
  }
}

Thank you. Happy coding.

Read more »

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it