public class SmithNumbers {
public static boolean isPrime(int number) {
int loop;
int prime = 1;
for(loop = 2; loop < number; loop++) {
if((number % loop) == 0) {
prime = 0;
}
}
if (prime == 1) {
return true;
} else {
return false;
}
}
public static ArrayList<Integer> primeFactors(int number) {
int sum = 0;
ArrayList al = new ArrayList();
for(int i = 2; i< number; i++) {
while(number % i == 0) {
System.out.println(i+" ");
al.add(i);
number = number/i;
}
}
if(number >2) {
System.out.println(number);
al.add(number);
}
return al;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number :");
int num = sc.nextInt();
int sum = 0;
@Coding_human
if(isPrime(num)) {
System.out.println("Given number is not smith number ");
} else {
ArrayList<Integer> arrayList = primeFactors(num);
System.out.println("Prime factors of the given number are"+arrayList);
Iterator it = arrayList.iterator();
while(it.hasNext()) {
int n = (int) it.next();
System.out.println(n);
while(n!=0) {
sum = sum+n%10;
n = n/10;
}
}
int temp = 0;
while(num != 0) {
temp = temp + num%10;
num = num/10;
}
System.out.println("sum of the digits of the numbers of the prime factorization: "+sum);
System.out.println("Sum of digits in the given number: "+temp);
if(temp==sum) {
System.out.println("Given number is a smith number");
} else {
System.out.println("Given number is not smith number ");
}
}
}
}
Java
Smith number Code
✅Telegram :@Coding_human
public static boolean isPrime(int number) {
int loop;
int prime = 1;
for(loop = 2; loop < number; loop++) {
if((number % loop) == 0) {
prime = 0;
}
}
if (prime == 1) {
return true;
} else {
return false;
}
}
public static ArrayList<Integer> primeFactors(int number) {
int sum = 0;
ArrayList al = new ArrayList();
for(int i = 2; i< number; i++) {
while(number % i == 0) {
System.out.println(i+" ");
al.add(i);
number = number/i;
}
}
if(number >2) {
System.out.println(number);
al.add(number);
}
return al;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number :");
int num = sc.nextInt();
int sum = 0;
@Coding_human
if(isPrime(num)) {
System.out.println("Given number is not smith number ");
} else {
ArrayList<Integer> arrayList = primeFactors(num);
System.out.println("Prime factors of the given number are"+arrayList);
Iterator it = arrayList.iterator();
while(it.hasNext()) {
int n = (int) it.next();
System.out.println(n);
while(n!=0) {
sum = sum+n%10;
n = n/10;
}
}
int temp = 0;
while(num != 0) {
temp = temp + num%10;
num = num/10;
}
System.out.println("sum of the digits of the numbers of the prime factorization: "+sum);
System.out.println("Sum of digits in the given number: "+temp);
if(temp==sum) {
System.out.println("Given number is a smith number");
} else {
System.out.println("Given number is not smith number ");
}
}
}
}
Java
Smith number Code
✅Telegram :@Coding_human
Please open Telegram to view this post
VIEW IN TELEGRAM
⭐️Technical and HR interviews material
https://bit.ly/3F98IDJ
Share our channel with your college friends : https://t.me/Coding_human
https://bit.ly/3F98IDJ
Share our channel with your college friends : https://t.me/Coding_human
Please open Telegram to view this post
VIEW IN TELEGRAM
ACCENTURE EXAM ALL SLOTS SOLUTION GROUP:
@Coding_human
https://t.me/accenture_all_slots_exam_code
✅ Share post in ur college Whatsapp grps.
@Coding_human
https://t.me/accenture_all_slots_exam_code
✅ Share post in ur college Whatsapp grps.
N = int(raw_input().strip())
if N % 2 != 0:
print "Weird" @Coding_human
else:
if N >= 2 and N <= 5:
print "Not Weird"
elif N >= 6 and N <= 20:
print "Weird"
elif N > 20:
print "Not Weird"
Tg : @Coding_human
if N % 2 != 0:
print "Weird" @Coding_human
else:
if N >= 2 and N <= 5:
print "Not Weird"
elif N >= 6 and N <= 20:
print "Weird"
elif N > 20:
print "Not Weird"
Tg : @Coding_human
N = int(raw_input().strip())
if N % 2 != 0:
print "Weird" @Coding_human
else:
if N >= 2 and N <= 5:
print "Not Weird"
elif N >= 6 and N <= 20:
print "Weird"
elif N > 20:
print "Not Weird"
Accenture exam ans
@Coding_human
if N % 2 != 0:
print "Weird" @Coding_human
else:
if N >= 2 and N <= 5:
print "Not Weird"
elif N >= 6 and N <= 20:
print "Weird"
elif N > 20:
print "Not Weird"
Accenture exam ans
@Coding_human
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
set<int> s;
for(int i=0;i<=n;i++)
{
int x;
cin>>x;
s.insert(x);
}
cout<<s.size();
return 0;
}
Primes with a twist Code
🔗 Telegram: @Coding_human
🔔Unmute this channel to never miss any updates
using namespace std;
int main() {
int n;
cin>>n;
set<int> s;
for(int i=0;i<=n;i++)
{
int x;
cin>>x;
s.insert(x);
}
cout<<s.size();
return 0;
}
Primes with a twist Code
🔗 Telegram: @Coding_human
🔔Unmute this channel to never miss any updates
Numerical
1. 5.505
2.9.99hrs
3.2:5
4.6002
5.25
6.83.25
7. 70, 71
8. I and II but not III
9.only ll
10.820
11) 91
Telegram - @Coding_human
1. 5.505
2.9.99hrs
3.2:5
4.6002
5.25
6.83.25
7. 70, 71
8. I and II but not III
9.only ll
10.820
11) 91
Telegram - @Coding_human
def flip( ch):
return '1' if (ch == '0') else '0'
# Utility method to get minimum flips when
# alternate string starts with expected char
def getFlipWithStartingCharcter(str, expected):
flipCount = 0
for i in range(len( str)):
# if current character is not expected,
# increase flip count
if (str[i] != expected):
flipCount += 1
# flip expected character each time
expected = flip(expected)
return flipCount
# method return minimum flip to make binary
# string alternate
def minFlipToMakeStringAlternate(str):
# return minimum of following two
# 1) flips when alternate string starts with 0
# 2) flips when alternate string starts with 1
return min(getFlipWithStartingCharcter(str, '0'),
//allcoding1 getFlipWithStartingCharcter(str, '1'))
# Driver code to test above method
if name == "main":
str = "0001010111"
print(minFlipToMakeStringAlternate)
Python
✅Telegram- @Coding_human
@Coding_human
return '1' if (ch == '0') else '0'
# Utility method to get minimum flips when
# alternate string starts with expected char
def getFlipWithStartingCharcter(str, expected):
flipCount = 0
for i in range(len( str)):
# if current character is not expected,
# increase flip count
if (str[i] != expected):
flipCount += 1
# flip expected character each time
expected = flip(expected)
return flipCount
# method return minimum flip to make binary
# string alternate
def minFlipToMakeStringAlternate(str):
# return minimum of following two
# 1) flips when alternate string starts with 0
# 2) flips when alternate string starts with 1
return min(getFlipWithStartingCharcter(str, '0'),
//allcoding1 getFlipWithStartingCharcter(str, '1'))
# Driver code to test above method
if name == "main":
str = "0001010111"
print(minFlipToMakeStringAlternate)
Python
✅Telegram- @Coding_human
@Coding_human
@Coding_human
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
5)graph
C
125 per
6)percentage of accidents
B
35000
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
5)graph
C
125 per
6)percentage of accidents
B
35000
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
10)some pencil
Neither consluion
D
11)slipa
B
Is nessecary
Telegram @Coding_human
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
@Coding_human
5)graph
C
125 per
6)percentage of accidents
B
35000
https://t.me/DMAD_Discussion
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
10)some pencil
Neither consluion
D
11)slipa
B
Is necessary
Telegram @Coding_human
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
5)graph
C
125 per
6)percentage of accidents
B
35000
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
5)graph
C
125 per
6)percentage of accidents
B
35000
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
10)some pencil
Neither consluion
D
11)slipa
B
Is nessecary
Telegram @Coding_human
1)some bats
Only conclusion 1 folows
D
2)jitin at present
The data in both
A
3)some parks
Nethier consluion 1.
4)ram's brother.
The data in both satesment
@Coding_human
5)graph
C
125 per
6)percentage of accidents
B
35000
https://t.me/DMAD_Discussion
7)deperments
C
100
8)all men are strong
Neither consluion.
A
9)class 6th grpah
D
100
10)some pencil
Neither consluion
D
11)slipa
B
Is necessary
Telegram @Coding_human