+ 1
Help me solve this to get output like this for m=7 n=14 for m=700 n=707 and.... n%3==2 , n/7=prime number
18 odpowiedzi
+ 3
There are a few issues with your code:
1. The for loop would stop at the first number bigger than 'm' that would not satisfy the condition n % 3 == 2.
2. You never reset 'x', so if one divisor is found, the condition x == 0 can never be true in the future.
3. You return the value of 'n' instead of printing it, resulting in no output even in case a number should be found.
Here is a corrected version of the code with some optimizations included by me:
https://code.sololearn.com/cW8mqYISLMR7/?ref=app
+ 3
Shadow do you have any idea about what this program is supposed to do? I mean, if you know wether the output has some mathematical value or is just the result of a problem made to practice.
+ 3
Your example seems to be inaccurate. You can't factorize m = 16 into two prime numbers, so I think you meant n = ab, which would then be n = 2 * 13 = 26 for m = 16, not n = 2 * 16.
Sure I could solve this, but how about you try it by yourself first? There are similarities to the first exercise, and if you studied my code, you should have an idea what you did wrong the first time when checking if a number is prime or not. You can always come back if you get stuck and I'll be happy to assist again, but I don't quite understand why I should do the entire exercise for you?
+ 3
If you tried, you surely have written a code that could serve as a starting point?
Here is a simple implementation:
Loop over the numbers starting at 'm' and check if the condition n % 3 == 2 is true. If it is, loop over the possible factors of 'n', which are all integers in the interval [2, n/2]. If a number 'i' divides 'n', i.e. n % i == 0 is true, then you check if it is prime. If it is, check if the number n / i is also prime. If both are prime, you found your number, otherwise you start over with n + 1.
+ 3
That's somewhat stupid, but nonetheless shouldn't be a problem, should it?
+ 2
Davide Well, what it does is that it calculates the next natural integer 'n' bigger than (or equal to, that is not quite clear from the examples) 'm', for which division by 3 yields a quotient of 2 and the quotient of division by 7 is a prime number.
I'm sure you could formalize this in a neat way and all, but if the resulting mapping has any staggering importance or interesting properties, I don't know it, if that is what you are asking. I'd deem it a practice problem, but I guess it also depends on where you draw the line between mathematical value and no mathematical value.
+ 2
I still fail to see why, but here is one possible implementation:
https://code.sololearn.com/c4jnu91ZKhHJ/?ref=app
+ 2
What do you mean, without function? There is no function being defined throughout the program.
+ 2
Sure, it doesn't matter in what base you write integer literals, as long as the values are the same. C supports binary (0b/0B), octary (0), decimal and hexadecimal (0x/0X) integer literals.
+ 1
Yes you are right it depends on where you draw the line.
My line is more or less between "it exists a Wikipedia's voice named after the sequence made with the possible outputs of this program" and "it doesn't"
From your explanation I guess it's a practice problem.
Thank you for answering!🤗🤗🤗
And nice job interpreting what the OP meant to ask 🤯
+ 1
Shadow thank you. Is it possible that i do it without using function?
+ 1
Why not?
0
Shadow thank for solving.but if m=ab and a and b both are prime number and n>m , n%3=2 . What is the lowest n ?
Example if m=16 n=26 n=2×16
Please solve this. Thank you🙏🙏🙏🙏
0
Shadow n=ab is correct and You're right.ok i tried but cant solve that. So if you can please solve it
0
Shadow the problem is i have to write than code without using function
0
Shadow i dont know if you can do it write it please . Thanks anyway
0
Shadow why numbers are in binary mode?
0
Shadow Can change them to normal usual number?