Click here to Skip to main content
15,560,073 members
Home / Discussions / Java
   

Java

 
QuestionRe: help with 2d cellular automata in JavaSwing Pin
Richard MacCutchan19-Nov-21 22:55
mveRichard MacCutchan19-Nov-21 22:55 
QuestionSending BufferedImage thought a socket Pin
Valentinor8-Oct-21 3:10
Valentinor8-Oct-21 3:10 
AnswerRe: Sending BufferedImage thought a socket Pin
jschell24-Oct-21 7:53
jschell24-Oct-21 7:53 
GeneralRe: Sending BufferedImage thought a socket Pin
Valentinor24-Oct-21 22:40
Valentinor24-Oct-21 22:40 
GeneralRe: Sending BufferedImage thought a socket Pin
jschell23-Dec-21 6:29
jschell23-Dec-21 6:29 
AnswerRe: Sending BufferedImage thought a socket Pin
Gerry Schmitz25-Oct-21 9:35
mveGerry Schmitz25-Oct-21 9:35 
AnswerRe: Sending BufferedImage thought a socket Pin
Joop Eggen 202125-Nov-21 7:15
Joop Eggen 202125-Nov-21 7:15 
QuestionJava Programming Challenge Pin
Purvesh Ptdr24-Sep-21 19:22
Purvesh Ptdr24-Sep-21 19:22 
For given numbers N and K, write a function to find 'significant number'. Let's look at an example to understand the steps to find 'significant number'.

Given N = 46333 and K = 3,



1. Check if N is 'reversible' or not. ['Reversible' denotes a number sequence that reads the same backward as forward, e.g., 12321]

If Yes, return 1.
If No, go to step 2.



2. Convert digits of N to elements of array A.
e.g. For N = 46333
Convert to array A = [4, 6, 3, 3, 3]



3. Replace each element of array A with its 'modified value'.
Modified value of A[ i ] = A[ i ] * 5;
Modified value of 4 is = 4*5 = 20
Modified value for 6 is = 6*5 = 30 and so on.



After replacing elements of array A with their 'modified values', array A will be [20, 30, 15, 15, 15]



4. For each element in the array generated in previous step, find the 'child primes' that are less than the array element. Then, generate the sum of these child primes.

A child prime is a number in the form (2 * p) + 1 where p is prime.

[Prime numbers are 2, 3, 5, 7, 11 ...]



For A[0] = 20,

for prime number 2, (2 * 2) + 1 = 5 < 20

for prime number 3, (2 * 3) + 1 = 7 < 20

for prime number 5, (2 * 5) + 1 = 11 < 20

for prime number 7, (2 * 7) + 1 = 15 < 20

for prime number 11, (2 * 11) + 1 = 23 > 20. Hence, will not consider 23.
So, child primes less than 20 are [5 7 11 15]. Sum of child primes for array element A[0] is = 38

Similarly for A[1] = 30, child primes that are less than 30 are [5 7 11 15 23 27]
Sum of child prime for array element A[1] is = 88 and so on.



Array is now = [38 88 23 23 23]



5. Count pairs of the array generated in previous step whose sum is divisible by value K=3.

Here pairs which are divisible by 3 are (38,88), (88,23), (88,23) and (88,23).

Hence, return 4. This is the 'significant number' to be returned.



Input

46333

3



where,

First line represents value of N
Second line represents value of K


Expected Output

4
QuestionRe: Java Programming Challenge Pin
Richard MacCutchan24-Sep-21 22:19
mveRichard MacCutchan24-Sep-21 22:19 
Questionjava jshell beanshell eval string Pin
Majid Karimi28-Aug-21 0:45
Majid Karimi28-Aug-21 0:45 
AnswerRe: java jshell beanshell eval string Pin
jschell5-Sep-21 9:55
jschell5-Sep-21 9:55 
QuestionDefault Casting a column to type using Hibernate Pin
ficevivu3-Aug-21 20:50
ficevivu3-Aug-21 20:50 
QuestionHow to make a scrolling background for a JPanel in java? Pin
Mr.Corona13-Jul-21 2:51
Mr.Corona13-Jul-21 2:51 
QuestionRe: How to make a scrolling background for a JPanel in java? Pin
Richard MacCutchan13-Jul-21 3:37
mveRichard MacCutchan13-Jul-21 3:37 
AnswerRe: How to make a scrolling background for a JPanel in java? Pin
Mr.Corona13-Jul-21 3:41
Mr.Corona13-Jul-21 3:41 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Richard MacCutchan13-Jul-21 3:46
mveRichard MacCutchan13-Jul-21 3:46 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Mr.Corona13-Jul-21 3:53
Mr.Corona13-Jul-21 3:53 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Richard MacCutchan13-Jul-21 4:04
mveRichard MacCutchan13-Jul-21 4:04 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Mr.Corona13-Jul-21 4:40
Mr.Corona13-Jul-21 4:40 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Richard MacCutchan13-Jul-21 6:02
mveRichard MacCutchan13-Jul-21 6:02 
GeneralRe: How to make a scrolling background for a JPanel in java? Pin
Mr.Corona13-Jul-21 18:55
Mr.Corona13-Jul-21 18:55 
QuestionHow to read a certificate from USB Token and Print It on Eclipse Console?? Pin
Member 150264029-Jul-21 1:59
Member 150264029-Jul-21 1:59 
QuestionKnowing about jdk Pin
Ranjeet Singh from Unknown7-Jul-21 22:56
Ranjeet Singh from Unknown7-Jul-21 22:56 
AnswerRe: Knowing about jdk Pin
Richard MacCutchan7-Jul-21 23:08
mveRichard MacCutchan7-Jul-21 23:08 
QuestionJava Pin
Ranjeet Singh from Unknown7-Jul-21 22:54
Ranjeet Singh from Unknown7-Jul-21 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.