×

Untouchable Number in Java

If a number N cannot be divided properly by any positive number, it is said to be an untouchable number. Additionally known as nonaliquot numbers. The sequence is A005114 from the OEIS.

It is a positive integer that cannot be represented as the sum of any positive integer's suitable divisors, unlike the untouchable number.

Properties

  •  A number that cannot be divided is not a perfect number.
  • All untouchable numbers are composite, with the exception of 2 and 5.

It is not an impossible number since the number 4 equals the total of the proper divisors of the number 9, i.e., 1+3 = 4.

Because it is not equal to the appropriate sum of any positive integer's divisors, the number 5 is untouchable. The only method to write 5 is as 1+4 in other words (there are no other ways). A number is equally divided by the digits 4 and 2. As a result, it is impossible to add 1+4 to any legitimate divisor.

The only odd untouchable number, as far as we can tell, is 5.

Steps to Solve an Untouchable Number

  1. Declare a number X.
  2. Find all the divisors of the given number X.
  3.  Verify whether the number x is untouchable if the sum of all its proper divisors equals x, or whether it is not.
  4. Check if i is the divisor of X or not:
    • If yes, add x to the variable a.
    • Else, add sum, x (divisor), and the resultant of (a/x) together.
    • At last, add 1 to the variable a.

Example:

The number 4 is not untouchable just because it is equal to the sum of the proper divisors of the number 9, for example, 1 + 3. The number 5 is untouchable because it does not equal the sum of the proper divisors of any positive integer.The only way to express 5 as the sum of distinct positive integers up to and including 1 is to write it as 5 = 1 + 4, but since 2 also divides by 4, it is impossible for 1 + 4 to equal the sum of all of a number's legitimate divisors (since the list of factors would have to contain both 4 and 2).

// java program to demonstrate untouchable number
import java.util.Scanner;  
public class solution
{  
//function determines the supplied number is an untouchable number or not.
static booleanisUntouchable(int x)  
{  
for(int n = 1; n<= 2 * x; n++)  
{  
if (sumOfDivisors(n) == x)  
return false;  
}  
return true;  
}    
static int sumOfDivisors(int a)  
{  
//stores the sum of the divisors  
int a = 0;  
//finds all the divisors of the number  
for(int n = 2; n<= Math.sqrt(a); n++)  
{  
// n is divisor of num  
if (a % n == 0)  
{  
//if equal, add only once, else add both  
if (n == (a / n))  
a = a + n;  
else  
a = a + (n + a / n);  
}  
}  
//1 is added to the variable sum because 1 is also a divisor  
return (a + 1);  
}  
//driver code  
public static void main(String args[])  
{  
Scanner s = new Scanner(System.in);  
System.out.print("given the number: ");  
int a =s.nextInt();  
//function calling  
if (isUntouchable(a))  
System.out.println("it’s an untouchable number. ");  
else  
System.out.println(" it’s not an untouchable number. ");  
}  
}  

Output:

Given the number: 2
It’s an untouchable number.
given the number: 25
It’s not an untouchable number.
// C++ program to demonstrate untouchable number
#include <bits/stdc++.h>
using namespace std;


// Function to determine the sum of all numeral appropriate divisors
int divSum(int a)
{
    // the total of the divisors' sum
    int res = 0;


    // Find all divisors of num
    for (int n = 2; n<= sqrt(a); n++) {


        // If 'n' is divisor of 'num'
        if (a % n == 0) {


            // Add it once if the two divisors are the same; otherwise, add them both.
            if (n == (a / n))
                res += n;
            else
                res += (n + a / n);
        }
    }


    // Given that 1 is also a divisor, add 1 to the result.
    return (res + 1);
}


// Checking whether X is an untouchable number function
bool isUntouchable(int x)
{
    for (int n = 1; n<= 2 * x; n++) {
        if (divSum(n) == x)
            return false;
    }
    return true;
}


// Driver Code
int main()
{
    // Given Number X
    int X = 52;


    // Function Call
    if (isUntouchable(x))
cout<< "Yes";
    else
cout<< "No";
}

Output:

Yes

Related Topics

Java String toUpperCase() methods

Java String toUpperCase() method is used to convert all the characters of the String into upper case. Syntax public String toUpperCase() public String toUpperCase(Locale locale) Returns It returns upper case String. Java String toUpperCase() Example 1: public...

1 minute read.

Java OCR

In this article, you will be acknowledged about what is a tesseract OCR, how it works, what are its used and advantages and disadvantages. Also, you will be able to...

4 minutes read.

Converting Roman to Integer Numerals in java

In this article, you will be acknowledged about the process of conversion of roman numbers to integers in java. The most important approaches are discussed and also the implementation of...

3 minutes read.

How to create a linked list in Java

Introduction: The linked listing is one type of linear statistics shaped like an array. Not like arrays, linked listing factors aren't stored in a contiguous place. The elements have linked...

3 minutes read.

Java CountDownLatch

Another crucial classes for concurrent execution is CountDownLatch. It is a synchronisation tool that enables one or more threads to await until a series of tasks started by another thread...

4 minutes read.

Java Calculate Average of List

The list is a linear data structure used in Java to store ordered data collections. Additionally, it accepts duplicate values while maintaining insertion order. It is sometimes necessary to find...

3 minutes read.

Java InetAddress class

InetAddress class The InetAddress class refers to the IP address, both IPv4 and IPv6.An instance of an InetAddress consists of an IP address and possibly its corresponding hostname. It provides a method to get the...

9 minutes read.

ConcurrentSkipListSet in Java

ConcurrentSkipListSet is a class that is a part of collection framework in Java.It has been available since Java version 1.6. ConcurrentSkipListSet  is a scalable concurrent NavigableSet implementation based on a ConcurrentSkipListMap.The...

16 minutes read.

Binary Strings Without Consecutive Ones in Java

N, an integer, is provided. Our objective is to determine the overall number of strings with length N that do not include successive 1s. Example: Input: 3 Output: 6 Explanation The binary forms of length...

6 minutes read.

How to declare string array in Java

Introduction Array is a data structure with a fixed size, which allows us to store elements of similar type. Data of primitive types like int, char, float, string, etc. can be...

2 minutes read.

Thread Concept in Java

What is a Thread? A subprocess that is lightweight in Java is known as a thread. It is the smallest unit of a process. For the running of multiple tasks parallelly...

3 minutes read.

Why we use static in Java

Many reserved keywords in Java cannot be used as variable names or identifiers. Java uses static keywords frequently because of its effective memory management system. In most cases, you must...

3 minutes read.

Java String replaceFirst() method

This method replace the first substring with user specified String. Syntax: public String replaceFirst(String Regexp, String Replacement) Parameter: Regexp : Regular Expression Replacement : the String which would replace found expression Return: a string Java String replaceFirst()...

1 minute read.

What’s New in Java 15

Sealed classes are the new concept that was introduced by Java 15. Sealed classes are a preview feature. Most of the features which are released in java 15 are in...

3 minutes read.

Java Integer reverseByte() method

The reverseByte() method of Java Integer class returns the value obtained by reversing the order of the bytes in the 2’s complement binary representation. Syntax public static int reverseByte (int i) Parameters The parameter...

1 minute read.

Constructor Program in Java

Constructor Program in Java In Java, a constructor is a piece of code that is used to create an object. A constructor is called implicitly when an object is created in...

7 minutes read.

Prime Number Program in Java

Prime Number Program in Java using for loop A natural number which is greater than 1 and has only two factors the number itself and 1 is called prime number. In...

2 minutes read.

Java For Loop

A for loop is used to execute a set of statements for a fixed number of times. It takes the following form: for (initialization; condition; update) { statements; } The for loop defines...

2 minutes read.

Java String getChars() Method

Java String getChars() method copies characters from current String to the destination character array . Syntax: public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex) Parameters: srcBegin - index of the first character...

1 minute read.

Java Integer reverse() method

The reverse() method of Java Integer class returns the value obtained by reversing the order of the bits in the 2’s complement binary representation. Syntax public static int reverse (int i)  Parameters The parameter...

1 minute read.