codeparrot/xlcost-text-to-code huggingface dataset:
Count of prime digits of a Number which divides the number | Java program to count number of digits which is prime and also divides number ; Function to find the number of digits in number which divides the number and is also a prime number ; Only 2 , 3 , 5 and 7 are prime one - digit number ; Loop to compute all the digits of the number untill it is not equal to the zero ; Fetching each digit of the number ; Checking if digit is greater than 0 and can divides n and is prime too ; Driven Code
class GFG { static int countDigit ( int n ) { boolean prime [ ] = new boolean [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) prime [ i ] = false ; prime [ 2 ] = prime [ 3 ] = true ; prime [ 5 ] = prime [ 7 ] = true ; int temp = n , count = 0 ; while ( temp != 0 ) { int d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 && prime [ d ] == true ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int n = 1032 ; System . out . println ( countDigit ( n ) ) ; } }
Bitwise Operations on Digits of a Number | Java implementation of the approach ; Function to find the digits ; Function to Find OR of all digits of a number ; Find OR of all digits ; return OR of digits ; Function to Find AND of all digits of a number ; Find AND of all digits ; return AND of digits ; Function to Find XOR of all digits of a number ; Find XOR of all digits ; return XOR of digits ; Driver code ; Find and store all digits ; Find XOR of digits ; Find OR of digits ; Find AND of digits ; Driver code
import java . util . * ; class GFG { static int [ ] digit = new int [ 100000 ] ; static int findDigits ( int n ) { int count = 0 ; while ( n != 0 ) { digit [ count ] = n % 10 ; n = n / 10 ; ++ count ; } return count ; } static int OR_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans | digit [ i ] ; } return ans ; } static int AND_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans & digit [ i ] ; } return ans ; } static int XOR_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans ^ digit [ i ] ; } return ans ; } static void bitwise_operation ( int N ) { int countOfDigit = findDigits ( N ) ; System . out . print ( " XOR ▁ = ▁ " + XOR_of_Digits ( N , countOfDigit ) + "NEW_LINE"); System . out . print ( " OR ▁ = ▁ " + OR_of_Digits ( N , countOfDigit ) + "NEW_LINE"); System . out . print ( " AND ▁ = ▁ " + AND_of_Digits ( N , countOfDigit ) + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 123456 ; bitwise_operation ( N ) ; } }
Length of longest subarray with product greater than or equal to 0 | Java implementation of the above approach ; Function that count the length of longest subarray with product greater than or equals to zero ; If product is greater than zero , return array size ; Traverse the array and if any negative element found then update the length of longest subarray with the length of left and right subarray ; Driver Code
import java . util . * ; public class GFG { static int maxLength ( int arr [ ] , int N ) { int product = 1 , len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { product *= arr [ i ] ; } if ( product >= 0 ) { return N ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { len = Math . max ( len , Math . max ( N - i - 1 , i ) ) ; } } return len ; } public static void main ( String args [ ] ) { int arr [ ] = { - 1 , 1 , 1 , - 2 , 3 , 2 , - 1 } ; int N = arr . length ; System . out . println ( maxLength ( arr , N ) ) ; } }
Print a pair of numbers with the given Sum and Product | Java program to find any pair which has sum S and product P . ; Prints roots of quadratic equation ax * 2 + bx + c = 0 ; calculating the sq root value for b * b - 4 * a * c ; Finding the roots ; Check if the roots are valid or not ; Finding the roots ; Check if the roots are valid or not ; when d < 0 ; No such pair exists in this case ; Driver code
import java . util . * ; class GFG { static void findRoots ( int b , int c ) { int a = 1 ; int d = b * b - 4 * a * c ; double sqrt_val = Math . sqrt ( Math . abs ( d ) ) ; if ( d > 0 ) { double x = - b + sqrt_val ; double y = - b - sqrt_val ; int root1 = ( int ) ( x ) / ( 2 * a ) ; int root2 = ( int ) ( y ) / ( 2 * a ) ; if ( root1 + root2 == - 1 * b && root1 * root2 == c ) System . out . print ( root1 + " , ▁ " + root2 ) ; else System . out . print ( - 1 ) ; } else if ( d == 0 ) { int root = - b / ( 2 * a ) ; if ( root + root == - 1 * b && root * root == c ) System . out . print ( root + " , ▁ " + root ) ; else System . out . print ( - 1 ) ; } else { System . out . print ( - 1 ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int S = 5 , P = 6 ; findRoots ( - S , P ) ; S = 5 ; P = 9 ; findRoots ( - S , P ) ; } }
Print N numbers such that their product is a Perfect Cube | Java program to find N numbers such that their product is a perfect cube ; Function to find the N numbers such that their product is a perfect cube ; Loop to traverse each number from 1 to N ; Print the cube of i as the ith term of the output ; Driver Code ; Function Call
import java . util . * ; class GFG { static void findNumbers ( int N ) { int i = 1 ; while ( i <= N ) { System . out . print ( ( i * i * i ) + " ▁ " ) ; i ++ ; } } public static void main ( String [ ] args ) { int N = 4 ; findNumbers ( N ) ; } }
Sum of all proper divisors from 1 to N | Java implementation to find sum of all proper divisor of number up to N ; Utility function to find sum of all proper divisor of number up to N ; Loop to iterate over all the numbers from 1 to N ; Find all divisors of i and add them ; Subtracting ' i ' so that the number itself is not included ; Driver Code
class GFG { static int properDivisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j * j <= i ; ++ j ) { if ( i % j == 0 ) { if ( i / j == j ) sum += j ; else sum += j + i / j ; } } sum = sum - i ; } return sum ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( properDivisorSum ( n ) ) ; n = 5 ; System . out . println ( properDivisorSum ( n ) ) ; } }
Sum of all proper divisors from 1 to N | Utility function to find sum of all proper divisor of number up to N ; Loop to find the proper divisor of every number from 1 to N ; Driver Code
class GFG { static int properDivisorSum ( int n ) { int sum = 0 ; int i ; for ( i = 1 ; i <= n ; ++ i ) sum += ( n / i ) * i ; return sum - n * ( n + 1 ) / 2 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( properDivisorSum ( n ) ) ; n = 5 ; System . out . println ( properDivisorSum ( n ) ) ; } }
Minimum change in given value so that it lies in all given Ranges | Java implementation find the minimum difference in the number D such that D is inside of every range ; Function to find the minimum difference in the number D such that D is inside of every range ; Loop to find the common range out of the given array of ranges . ; Storing the start and end index ; Sorting the range ; Finding the maximum starting value of common segment ; Finding the minimum ending value of common segment ; If there is no common segment ; If the given number is between the computed common range . ; Finding the minimum distance ; Driver Code ; Given array of ranges
import java . util . * ; class GFG { static void findMinimumOperation ( int n , int d , int arrays [ ] [ ] ) { int cnt = 0 ; int first = Integer . MIN_VALUE , end = Integer . MAX_VALUE ; while ( n > 0 ) { int arr [ ] = { arrays [ cnt ] [ 0 ] , arrays [ cnt ] [ 1 ] } ; Arrays . sort ( arr ) ; first = Math . max ( first , arr [ 0 ] ) ; end = Math . min ( end , arr [ 1 ] ) ; cnt ++ ; n -- ; } if ( first > end ) System . out . print ( " - 1" ) ; else { if ( d >= first && d <= end ) { System . out . print ( "0" ) ; } else System . out . print ( Math . min ( Math . abs ( first - d ) , Math . abs ( d - end ) ) ) ; } } public static void main ( String [ ] args ) { int n = 3 , d = 3 ; int arrays [ ] [ ] = { { 0 , 7 } , { 2 , 14 } , { 4 , 6 } } ; findMinimumOperation ( n , d , arrays ) ; } }
Number of factors of very large number N modulo M where M is any prime number | Java implementation to find the Number of factors of very large number N modulo M ; Function for modular multiplication ; Function to find the number of factors of large Number N ; Count the number of times 2 divides the number N ; Condition to check if 2 divides it ; Check for all the possible numbers that can divide it ; Loop to check the number of times prime number i divides it ; Condition to check if prime number i divides it ; Condition to check if N at the end is a prime number . ; Driver Code
class GFG { static long mod = 1000000007L ; static long mult ( long a , long b ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; } static long calculate_factors ( long n ) { long ans , cnt ; cnt = 0 ; ans = 1 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } for ( int i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { cnt = 0 ; while ( n % i == 0 ) { cnt ++ ; n = n / i ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } } if ( n > 2 ) { ans = mult ( ans , ( 2 ) ) ; } return ans % mod ; } public static void main ( String [ ] args ) { long n = 193748576239475639L ; mod = 17 ; System . out . print ( calculate_factors ( n ) + "NEW_LINE"); } }
Maximum value of B less than A such that A ^ B = A + B | Function to find the maximum value of B such that A ^ B = A + B ; Binary Representation of A ; Loop to find the negation of the integer A ; output ; Driver Code ; Function Call
class GFG { static void maxValue ( int a ) { String c = Integer . toBinaryString ( a ) ; String b = " " ; for ( int i = 0 ; i < c . length ( ) ; i ++ ) { if ( ( c . charAt ( i ) - '0' ) == 1 ) b += '0' ; else b += '1' ; } System . out . print ( Integer . parseInt ( b , 2 ) ) ; } public static void main ( String [ ] args ) { int a = 4 ; maxValue ( a ) ; } }
Print all possible pair with prime XOR in the Array | Java implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to print all Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then print this pair ; Driver Code ; Generate all the prime number ; Function Call
class GFG { static int sz = ( int ) 1e5 ; static boolean [ ] isPrime = new boolean [ sz + 1 ] ; static void generatePrime ( ) { int i , j ; for ( i = 2 ; i <= sz ; i ++ ) isPrime [ i ] = true ; for ( i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } static void Pair_of_PrimeXor ( int A [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) { System . out . print ( " ( " + A [ i ] + " , ▁ " + A [ j ] + " ) ▁ " ) ; } } } } public static void main ( String [ ] args ) { int A [ ] = { 1 , 3 , 6 , 11 } ; int n = A . length ; generatePrime ( ) ; Pair_of_PrimeXor ( A , n ) ; } }
Check if N can be expressed as product of 3 distinct numbers | Java program to find the three numbers ; function to find 3 distinct number with given product ; Declare a vector to store divisors ; store all divisors of number in array ; store all the occurence of divisors ; check if n is not equals to - 1 then n is also a prime factor ; Initialize the variables with 1 ; check for first number a ; check for second number b ; check for third number c ; check for all unwanted condition ; Driver function
import java . util . * ; class GFG { static void getnumbers ( int n ) { Vector < Integer > divisor = new Vector < Integer > ( ) ; for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . add ( i ) ; n /= i ; } } if ( n != 1 ) { divisor . add ( n ) ; } int a , b , c , size ; a = b = c = 1 ; size = divisor . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( a == 1 ) { a = a * divisor . get ( i ) ; } else if ( b == 1 b == a ) { b = b * divisor . get ( i ) ; } else { c = c * divisor . get ( i ) ; } } if ( a == 1 b == 1 c == 1 a == b b == c a == c ) { System . out . print ( " - 1" + "NEW_LINE"); } else { System . out . print ( a + " ▁ " + b + " ▁ " + c + "NEW_LINE"); } } public static void main ( String [ ] args ) { int n = 64 ; getnumbers ( n ) ; } }
Check if all Prime factors of number N are unique or not | Java program for the above approach ; Function that returns the all the distinct prime factors in a vector ; If n is divisible by 2 ; Divide n till all factors of 2 ; Check for the prime numbers other than 2 ; Store i in Prime [ ] i is a factor of n ; Divide n till all factors of i ; If n is greater than 2 , then n is prime number after n divided by all factors ; Returns the vector Prime ; Function that check whether N is the product of distinct prime factors or not ; Returns the vector to store all the distinct prime factors ; To find the product of all distinct prime factors ; Find the product ; If product is equals to N , print YES , else print NO ; Driver Code
import java . util . * ; class GFG { static Vector < Integer > primeFactors ( int n ) { int i , j ; Vector < Integer > Prime = new Vector < Integer > ( ) ; if ( n % 2 == 0 ) { Prime . add ( 2 ) ; } while ( n % 2 == 0 ) { n = n / 2 ; } for ( i = 3 ; i <= Math . sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { Prime . add ( i ) ; } while ( n % i == 0 ) { n = n / i ; } } if ( n > 2 ) { Prime . add ( n ) ; } return Prime ; } static void checkDistinctPrime ( int n ) { Vector < Integer > Prime = primeFactors ( n ) ; int product = 1 ; for ( int i : Prime ) { product *= i ; } if ( product == n ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } public static void main ( String [ ] args ) { int N = 30 ; checkDistinctPrime ( N ) ; } }
Count perfect power of K in a range [ L , R ] | Java implementation to find the count of numbers those are powers of K in range L to R ; Function to find the Nth root of the number ; initially guessing a random number between 0 to 9 ; Smaller eps , denotes more accuracy ; Initializing difference between two roots by Integer . MAX_VALUE ; xK denotes current value of x ; loop until we reach desired accuracy ; calculating current value from previous value ; Function to count the perfect powers of K in range L to R ; Driver code
class GFG { static double nthRoot ( int A , int N ) { double xPre = Math . random ( ) * 10 % 10 ; double eps = 1e-3 ; double delX = Integer . MAX_VALUE ; double xK = 0 ; while ( delX > eps ) { xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ; delX = Math . abs ( xK - xPre ) ; xPre = xK ; } return xK ; } static int countPowers ( int a , int b , int k ) { return ( int ) ( Math . floor ( nthRoot ( b , k ) ) - Math . ceil ( nthRoot ( a , k ) ) + 1 ) ; } public static void main ( String [ ] args ) { int a = 7 , b = 28 , k = 2 ; System . out . print ( " Count ▁ of ▁ Powers ▁ is ▁ " + countPowers ( a , b , k ) ) ; } }
Minimum number of primes required such that their sum is equal to N | Java program for the above approach ; Function to check if n is prime ; Function to count the minimum prime required for given sum N ; Case 1 : ; Case 2 : ; Case 3 : ; Case 3 a : ; Case 3 b : ; Driver Code ; Function Call
class GFG { static boolean isPrime ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } static void printMinCountPrime ( int N ) { int minCount ; if ( isPrime ( N ) ) { minCount = 1 ; } else if ( N % 2 == 0 ) { minCount = 2 ; } else { if ( isPrime ( N - 2 ) ) { minCount = 2 ; } else { minCount = 3 ; } } System . out . print ( minCount + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 100 ; printMinCountPrime ( N ) ; } }
Long Division Method to find Square root with Examples | Java program to find the square root of a number by using long division method ; Function to find the square root of a number by using long division method ; int i = 0 , udigit , j ; Loop counters ; Dividing the number into segments ; Last index of the array of segments ; Start long division from the last segment ( j = i ) ; Initialising the remainder to the maximum value ; Including the next segment in new dividend ; Loop to check for the perfect square closest to each segment ; This condition is to find the divisor after adding a digit in the range 0 to 9 ; Calculating the remainder ; Updating the units digit of the quotient ; Adding units digit to the quotient ; New divisor is two times quotient ; Including the remainder in new dividend ; Driver code
import java . util . * ; class GFG { static final int INFINITY_ = 9999999 ; static int sqrtByLongDivision ( int n ) { int cur_divisor = 0 ; int quotient_units_digit = 0 ; int cur_quotient = 0 ; int cur_dividend = 0 ; int cur_remainder = 0 ; int a [ ] = new int [ 10 ] ; while ( n > 0 ) { a [ i ] = n % 100 ; n = n / 100 ; i ++ ; } i -- ; for ( j = i ; j >= 0 ; j -- ) { cur_remainder = INFINITY_ ; cur_dividend = cur_dividend * 100 + a [ j ] ; for ( udigit = 0 ; udigit <= 9 ; udigit ++ ) { if ( cur_remainder >= cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) && cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) >= 0 ) { cur_remainder = cur_dividend - ( ( cur_divisor * 10 + udigit ) * udigit ) ; quotient_units_digit = udigit ; } } cur_quotient = cur_quotient * 10 + quotient_units_digit ; cur_divisor = cur_quotient * 2 ; cur_dividend = cur_remainder ; } return cur_quotient ; } public static void main ( String [ ] args ) { int x = 1225 ; System . out . print ( sqrtByLongDivision ( x ) + "NEW_LINE"); } }
Count of consecutive Fibonacci pairs in the given Array | Java implementation to count the consecutive fibonacci pairs in the array ; Function to find the previous fibonacci for the number N ; Function to find the next fibonacci number for the number N ; Function to check that a Number is a perfect square or not ; Function to check that a number is fibonacci number or not ; N is Fibinacci if one of ( 5 * n * n + 4 ) or ( 5 * n * n - 4 ) is a perferct square ; Function to count the fibonacci pairs in the array ; Loop to iterate over the array to choose all pairs of the array ; Condition to check if both the number of pair is a fibonacci number ; Condition to check if both the number form consecutive fibonacci numbers ; Driver Code
import java . util . * ; import java . lang . * ; class GFG { static int previousFibonacci ( int n ) { double a = n / ( ( 1 + ( int ) Math . sqrt ( 5 ) ) / 2.0 ) ; return ( int ) Math . round ( a ) ; } static int nextFibonacci ( int n ) { double a = n * ( 1 + ( int ) Math . sqrt ( 5 ) ) / 2.0 ; return ( int ) Math . round ( a ) ; } static boolean isPerfectSquare ( int x ) { int s = ( int ) Math . sqrt ( x ) ; return ( s * s == x ) ; } static boolean isFibonacci ( int n ) { return ( isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ) ; } static int countFibonacciPairs ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( isFibonacci ( arr [ i ] ) && isFibonacci ( arr [ j ] ) ) { int prevFib = previousFibonacci ( arr [ i ] ) ; int nextFib = nextFibonacci ( arr [ i ] ) ; if ( prevFib == arr [ j ] nextFib == arr [ j ] ) { res ++ ; } } return res ; } public static void main ( String [ ] args ) { int [ ] a = { 3 , 5 , 8 , 11 } ; int n = a . length ; System . out . print ( countFibonacciPairs ( a , n ) ) ; } }
Count all distinct pairs with product equal to K | Java program to count the number of pairs whose product is equal to K ; Function to count the number of pairs whose product is equal to K ; Pick all elements one by one ; Check if the product of this pair is equal to K ; Driver code
class GFG { static int countPairsWithProdK ( int arr [ ] , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] * arr [ j ] == k ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int N = arr . length ; int K = 3 ; System . out . println ( countPairsWithProdK ( arr , N , K ) ) ; } }
Count all distinct pairs with product equal to K | Java program to count the number of pairs whose product is equal to K ; Function to count the number of pairs whose product is equal to K ; Initialize the count ; Initialize empty hashmap . ; Insert array elements to hashmap ; Checking if the index is a whole number and present in the hashmap ; Driver code
class GFG { static int MAX = 100000 ; static int countPairsWithProductK ( int arr [ ] , int n , int k ) { int count = 0 ; int i ; boolean hashmap [ ] = new boolean [ MAX ] ; for ( i = 0 ; i < n ; i ++ ) hashmap [ arr [ i ] ] = true ; for ( i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; double index = 1.0 * k / arr [ i ] ; if ( index >= 0 && ( ( index - ( int ) ( index ) ) == 0 ) && hashmap [ k / x ] ) count ++ ; hashmap [ x ] = false ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int N = arr . length ; int K = 3 ; System . out . print ( countPairsWithProductK ( arr , N , K ) ) ; } }
Find any K distinct odd integers such that their sum is equal to N | Java implementation to find k odd integers such that their sum is N ; Function to find K odd integers such that their sum is N ; Condition to check if there exist such K integers ; Loop to find first K - 1 distinct odd integers ; Final Kth odd number ; Driver code
class GFG { static void oddIntegers ( int n , int k ) { if ( n % 2 != k % 2 ) { System . out . println ( " - 1" ) ; return ; } int sum = 0 ; int i = 1 ; int j = 1 ; while ( j < k ) { sum = sum + i ; System . out . print ( i + " ▁ " ) ; i = i + 2 ; j ++ ; } int finalOdd = n - sum ; System . out . println ( finalOdd ) ; } public static void main ( String [ ] args ) { int n = 10 ; int k = 2 ; oddIntegers ( n , k ) ; } }
Sum of product of proper divisors of all Numbers lying in range [ L , R ] | Java implementation to find the sum of the product of proper divisors of all the numbers lying in the range [ L , R ] ; Vector to store the product of the proper divisors of a number ; Variable to store the prefix sum of the product array ; Function to precompute the product of proper divisors of a number at it 's corresponding index ; Modificatino of sieve to store the product of the proper divisors ; Multiplying the existing value with i because i is the proper divisor of ans [ j ] ; Loop to store the prefix sum of the previously computed product array ; Computing the prefix sum ; Function to print the sum for each query ; Function to print te sum of product of proper divisors of a number in [ L , R ] ; Calling the function that pre computes the sum of product of proper divisors ; Iterate over all Queries to print the sum ; Driver code
import java . util . * ; class GFG { static int mod = 1000000007 ; static int [ ] ans = new int [ 100002 ] ; static int [ ] pref = new int [ 100002 ] ; static void preCompute ( ) { Arrays . fill ( ans , 1 ) ; for ( int i = 2 ; i <= 100000 / 2 ; i ++ ) { for ( int j = 2 * i ; j <= 100000 ; j += i ) { ans [ j ] = ( ans [ j ] * i ) % mod ; } } for ( int i = 1 ; i < 100002 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + ans [ i ] ; pref [ i ] %= mod ; } } static void printSum ( int L , int R ) { System . out . print ( pref [ R ] - pref [ L - 1 ] + " ▁ " ) ; } static void printSumProper ( int [ ] [ ] arr , int Q ) { preCompute ( ) ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } public static void main ( String args [ ] ) { int Q = 2 ; int [ ] [ ] arr = { { 10 , 20 } , { 12 , 16 } } ; printSumProper ( arr , Q ) ; } }