Tcefrep Number a number N such that reverse(n) = sum of the proper divisors of N.
6, 498906, 20671542, 41673714….
Check if N is a Tcefrep number
Given a number N, the task is to check if N is a Tcefrep Number or not. If N is an Tcefrep Number then print “Yes” else print “No”.
Examples:
Input: N = 498906
Output: Yes
Explanation:
proper divisors of 498906 are 1, 2, 3, 6, 9, 18, 27, 54,
9239, 18478, 27717, 55434, 83151, 166302, 249453,
which sum to 609894, the reverse of 498906
Input: N = 120
Output: No
Approach:
- We will find the sum of proper divisors of N
- We will find the reverse of N
- Then we will check if sum of proper divisors of N is equal to reverse of N or not, if equal then print “Yes” else print “No”.
Below is the implementation of the above approach:
// C++ implementation to check if N // is a Tcefrep number #include <bits/stdc++.h> using namespace std;
// Iterative function to // reverse digits of num int reverse( int num)
{ int rev_num = 0;
while (num > 0)
{
rev_num = rev_num*10 + num%10;
num = num/10;
}
return rev_num;
} // Function to calculate sum of // all proper divisors // num --> given natural number int properDivSum( int num)
{ // Final result of summation of divisors
int result = 0;
// find all divisors which divides 'num'
for ( int i=2; i<= sqrt (num); i++)
{
// if 'i' is divisor of 'num'
if (num%i==0)
{
// if both divisors are same then add
// it only once else add both
if (i==(num/i))
result += i;
else
result += (i + num/i);
}
}
// Add 1 to the result as 1 is also a divisor
return (result + 1);
} bool isTcefrep( int n)
{ return properDivSum(n) == reverse(n);
} // Driver Code int main()
{ // Given Number N
int N = 6;
// Function Call
if (isTcefrep(N))
cout << "Yes" ;
else
cout << "No" ;
return 0;
} |
// Java program for above approach class GFG{
// Iterative function to // reverse digits of num static int reverse( int num)
{ int rev_num = 0 ;
while (num > 0 )
{
rev_num = rev_num * 10 + num % 10 ;
num = num / 10 ;
}
return rev_num;
} // Function to calculate sum of // all proper divisors // num --> given natural number static int properDivSum( int num)
{ // Final result of summation of divisors
int result = 0 ;
// find all divisors which divides 'num'
for ( int i = 2 ; i<= Math.sqrt(num); i++)
{
// if 'i' is divisor of 'num'
if (num % i == 0 )
{
// if both divisors are same then add
// it only once else add both
if (i == (num / i))
result += i;
else
result += (i + num / i);
}
}
// Add 1 to the result as 1
// is also a divisor
return (result + 1 );
} static boolean isTcefrep( int n)
{ return properDivSum(n) == reverse(n);
} // Driver Code public static void main(String[] args)
{ int N = 6 ;
// Function Call
if (isTcefrep(N))
System.out.print( "Yes" );
else
System.out.print( "No" );
} } // This code is contributed by Pratima Pandey |
# Python3 implementation to check if N # is a Tcefrep number import math
# Iterative function to # reverse digits of num def reverse(num):
rev_num = 0
while (num > 0 ):
rev_num = rev_num * 10 + num % 10
num = num / / 10
return rev_num
# Function to calculate sum of # all proper divisors # num --> given natural number def properDivSum(num):
# Final result of summation of divisors
result = 0
# find all divisors which divides 'num'
for i in range ( 2 , ( int )(math.sqrt(num)) + 1 ):
# if 'i' is divisor of 'num'
if (num % i = = 0 ):
# if both divisors are same then add
# it only once else add both
if (i = = (num / / i)):
result + = i
else :
result + = (i + num / i)
# Add 1 to the result as 1 is also a divisor
return (result + 1 )
def isTcefrep(n):
return properDivSum(n) = = reverse(n);
# Driver Code # Given Number N N = 6
# Function Call if (isTcefrep(N)):
print ( "Yes" )
else :
print ( "No" )
# This code is contributed by Sanjit Prasad |
// C# program for above approach using System;
class GFG{
// Iterative function to // reverse digits of num static int reverse( int num)
{ int rev_num = 0;
while (num > 0)
{
rev_num = rev_num * 10 + num % 10;
num = num / 10;
}
return rev_num;
} // Function to calculate sum of // all proper divisors // num --> given natural number static int properDivSum( int num)
{ // Final result of summation of divisors
int result = 0;
// find all divisors which divides 'num'
for ( int i = 2; i<= Math.Sqrt(num); i++)
{
// if 'i' is divisor of 'num'
if (num % i == 0)
{
// if both divisors are same then add
// it only once else add both
if (i == (num / i))
result += i;
else
result += (i + num / i);
}
}
// Add 1 to the result as 1
// is also a divisor
return (result + 1);
} static bool isTcefrep( int n)
{ return properDivSum(n) == reverse(n);
} // Driver Code public static void Main()
{ int N = 6;
// Function Call
if (isTcefrep(N))
Console.Write( "Yes" );
else
Console.Write( "No" );
} } // This code is contributed by Nidhi_Biet |
<script> // Javascript program for above approach // Iterative function to
// reverse digits of num
function reverse( num) {
let rev_num = 0;
while (num > 0) {
rev_num = rev_num * 10 + num % 10;
num = parseInt(num / 10);
}
return rev_num;
}
// Function to calculate sum of
// all proper divisors
// num --> given natural number
function properDivSum( num) {
// Final result of summation of divisors
let result = 0;
// find all divisors which divides 'num'
for ( i = 2; i <= Math.sqrt(num); i++) {
// if 'i' is divisor of 'num'
if (num % i == 0) {
// if both divisors are same then add
// it only once else add both
if (i == (num / i))
result += i;
else
result += (i + num / i);
}
}
// Add 1 to the result as 1
// is also a divisor
return (result + 1);
}
function isTcefrep( n) {
return properDivSum(n) == reverse(n);
}
// Driver Code
let N = 6;
// Function Call
if (isTcefrep(N))
document.write( "Yes" );
else
document.write( "No" );
// This code contributed by gauravrajput1 </script> |
Yes
Time Complexity: O(n^2)
Reference: http://www.numbersaplenty.com/set/tcefrep_number/