nana

                Never    
Java
       









<!doctype html>
<html>
<head>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-YG43LG3PGY"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'G-YG43LG3PGY');
    </script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>cl1p.net - The internet clipboard</title>
    <link href='/sys/global.css' rel='stylesheet'>
    <script src="/sys/cl1phelper.js"></script>
</head>
<body onload="go()">


<div class="wrapperStyle">
    <div id="desktopHeader">
    <div style="float:left"><a href="/">cl1p.net - The internet clipboard</a>&nbsp;
    </div>
        <div style="float:right">
            
            <a class='loginSignUp' href='/sys/login.jsp'>Login/Sign Up</a>
            
            cl1p.net/600
        </div>
        <div style="clear:both"></div>
    </div>
    <div id="mobileHeader">
        <div>cl1p.net/600 
        </div>
        <div>
        </div>
        <div style="float:right">
            
            <a class='loginSignUp' href='/sys/login.jsp'>Login/Sign Up</a>
            
        </div>
        <div style="clear:both"></div>
    </div>







<script src="/sys/cl1phelper.js"></script>
<div class="line"></div>

<div class="statusLine"><span>This cl1p will be deleted in in 25 days.</span>
    
    <button  id="copyToClipboardBtn">Copy</button>
</div>
<div class="contentRead" id="target">
        <textarea id="cl1pTextArea" name="content">

//Sieve Algorithm

import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the Upper Bound");
        int n = sc.nextInt();
        boolean[] array = new boolean[n + 1];

        for (int i = 2; i <= n; i++) {
            array[i] = true;
        }

        for (int i = 2; i * i <= n; i++) {
            if (array[i]) {
                for (int j = i * i; j <= n; j += i) {
                    array[j] = false;
                }
            }
        }

        System.out.println("Prime numbers from 2 to " + n + ":");
        for (int i = 2; i <= n; i++) {
            if (array[i]) {
                System.out.print(i + " ");
            }
        }
    }
}


//Segmented Sieve Algorithm

import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        System.out.println("Enter the lower Bound");
        int l = sc.nextInt();
        
        System.out.println("Enter the Upper Bound");
        int n = sc.nextInt();
        
        boolean[] array = new boolean[n + 1];
        
        for (int i = 2; i <= n; i++) {
            array[i] = true;
        }
        
        for (int i = 2; i * i <= n; i++) {
            if (array[i]) {
                for (int j = i * i; j <= n; j += i) {
                    array[j] = false;
                }
            }
        }
        
        System.out.println("Prime numbers from " + l + " to " + n + ":");
        
        for (int i = l; i <= n; i++) {
            if (array[i]) {
                System.out.print(i + " ");
            }
        }
    }
}


//Euler's phi Algorithm

import java.util.*;

public class tcs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the N Value");
        int n = sc.nextInt();
        
        for (int i = 1; i <= n; i++) {
            int c = 0;
            
            for (int j = 1; j <= i; j++) {
                if (gcd(j, i) == 1) {
                    c++;
                }
            }
            
            System.out.println("phi(" + i + ") = " + c);
        }
    }
    
    static int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }
}


//Strobogrammatic Number

import java.util.*;

public class tcs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number");
        String num = sc.next();
        String s1 = "";
        
        for (int i = 0; i < num.length(); i++) {
            char c = num.charAt(i);
            
            if (c == '0') {
                s1 = '0' + s1;
            } else if (c == '1') {
                s1 = '1' + s1;
            } else if (c == '6') {
                s1 = '9' + s1;
            } else if (c == '8') {
                s1 = '8' + s1;
            } else if (c == '9') {
                s1 = '6' + s1;
            }
        }
        
        if (s1.equals(num)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


// Remainder Theorem

import java.util.*;

class tcs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d[] = new int[n];
        
        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
        }
        
        int r[] = new int[n];
        
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        
        int j, x = 1;
        
        while (true) {
            for (j = 0; j < n; j++) {
                if (x % d[j] != r[j]) {
                    break;
                }
            }
            
            if (j == n) {
                System.out.println(x);
                break;
            }
            
            x++;
        }
    }
}


// Toggle the switch

import java.util.*;

public class tcs {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Switch Count");
        int n = sc.nextInt();
        boolean switches[] = new boolean[n + 1];
        int onCount = 0;
        int offCount = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                if (switches[j] == false)
                    switches[j] = true;
                else
                    switches[j] = false;
            }
        }

        for (int k = 1; k <= n; k++) {
            if (switches[k] == true)
                onCount++;
            else
                offCount++;
        }

        System.out.println("On count " + onCount);
        System.out.println("Off Count " + offCount);
    }
}


//: Alice Apple Tree

import java.util.*;

public class tcs {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Apple Count");
        int apple = sc.nextInt();
        int s = 0, c = 0;

        while (s < apple) {
            c = c + 1;
            s = s + 12 * (c * c);
        }

        System.out.println(c * 8);
    }
}


//Binary Palindrome

import java.util.*;

public class tcs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number");
        int n = sc.nextInt();
        String s1 = "";
        String s2 = "";

        while (n > 0) {
            s1 = n % 2 + s1;
            s2 = s2 + n % 2;
            n = n / 2;
        }

        if (s1.equals(s2)) {
            System.out.println("Binary Palindrome");
        } else {
            System.out.println("Not Binary Palindrome");
        }
    }
}


//Booth’s Algorithm

import java.util.*;

public class tcs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the Multiplier");
        int a = sc.nextInt();
        System.out.println("Enter the Multiplicand");
        int b = sc.nextInt();
        int p = 0;
        int c = 0;
        
        if (a < 0) {
            a = -1 * (a);
            c++;
        }
        
        if (b < 0) {
            b = -1 * (b);
            c++;
        }
        
        while (a > 0) {
            if (a % 2 == 1) {
                p = p + b;
            }
            a = a >> 1;
            b = b << 1;
        }
        
        if (c == 1) {
            System.out.println("Result " + (-1 * p));
        } else {
            System.out.print("Result " + p);
        }
    }
}


//Euclidean Algorithm

import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the Number 1");
        int number1 = sc.nextInt();
        System.out.println("Enter the Number 2");
        int number2 = sc.nextInt();
        System.out.println(gcd(number1, number2));
    }
    
    static int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        return gcd(b % a, a);
    }
}


//Karatsuba Algorithm

import java.util.*;

public class tcs {
    public static void main(String s[]) {
        Scanner sw = new Scanner(System.in);
        long x = sw.nextLong();
        long y = sw.nextLong();
        System.out.println(k(x, y));
    }

    static long k(long x, long y) {
        if (x < 10 && y < 10) {
            return x * y;
        }

        long n = Math.max(String.valueOf(x).length(), String.valueOf(y).length());
        long n1 = n / 2;
        long a = x / (long) Math.pow(10, n1);
        long b = x % (long) Math.pow(10, n1);
        long c = y / (long) Math.pow(10, n1);
        long d = y % (long) Math.pow(10, n1);

        long s1 = k(a, c);
        long s2 = k(b, d);
        long s3 = k(a + b, c + d);
        long s4 = s3 - s2 - s1;
        long res = s1 * (long) Math.pow(10, 2 * n1) + s4 * (long) Math.pow(10, n1) + s2;
        
        return res;
    }
}


//: Longest Sequence of 1 after flipping a bit


import java.util.Scanner;

public class tcs {
    public static void main(String[] args) {
        Scanner sw = new Scanner(System.in);
        int num = sw.nextInt();
        String s = Integer.to

img
close

Raw Text