-4

I have written an algorithm, for the task at hand. Here's its condition: Valera the Horse has an integer n. Also Valera has hooves. It is difficult to write with hooves, so Valera can only write the numbers one ("1") and two ("2").

Now Valera wants to find a positive integer which will divide by 2n without remainder and at the same time will contain exactly n digits in the decimal notation. Of course, the decimal notation of this number must not contain any digits except ones and twos.

Help Valera, find and print the required number.

Input data The first line contains an integer n (1 ≤ n ≤ 50) - Valera's number.

Output data Print a positive integer in decimal notation consisting of n digits, which will be divisible by 2n. The decimal notation of this number can contain only ones and twos.

It is guaranteed that an answer exists. If more than one answer exists, it is allowed to output any answer.

Examples Input example 1 Output example 2

Here's my solution:

from itertools import product

n = int(input())
for p in product("12", repeat=n):
    res = ''.join(p)
    if len(res) == n and int(res) % (n*2) == 0:
        print(res)
        break

Please point out where my mistake is

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • The code you posted is not C++. How can we help you with your C++ code when you don't post any? You don't even talk about mixing C++ with Python. So why the C++ tag. – Thomas Matthews Aug 24 '23 at 20:17
  • This tag means that the code can be rewritten in C++ if it is necessary for faster solution of this task – FIma Dev Aug 24 '23 at 20:23
  • Since you tagged as C++ (which means you are programming in C++), here are some mistakes: 1) C++ does not have the `from` keyword. 2) The code is not encapsulated into a function (`main` or otherwise). 3) The variable `n` and `p` are not typed and not defined. 4) There is no variable or type, `''`, so the compiler can't find the `join` member. 5) The `:` is used incorrectly; use `;` to terminate and separate statements. 6) For multiple statements in a loop, use `{` and `}`. 7) `res` has no type, so it can't be converted to an `int`. – Thomas Matthews Aug 24 '23 at 20:23
  • Requesting code is off-topic for StackOverflow. Maybe try [softwarerecs.se]? – Thomas Matthews Aug 24 '23 at 20:26
  • @ThomasMatthews cruel but funny – hraban Aug 24 '23 at 20:37
  • SO is toxic.... – Christoph Aug 24 '23 at 20:43
  • Your code works perfectly. Why do you think it doesn't? – Tim Roberts Aug 24 '23 at 20:50
  • The code works fine, but it only passes 4% of the tests on the site, I don't understand what the problem is. Here is the task in full: https://www.eolymp.com/en/problems/4648 – FIma Dev Aug 24 '23 at 20:54
  • That doesn't make sense. It works correctly for all numbers except those where no answer exists (which means any multiple of 5), but the problem statement says a solution is guaranteed to exist. Are you getting a time limit or a memory limit? – Tim Roberts Aug 24 '23 at 21:01
  • No, the problems are purely in the answers – FIma Dev Aug 24 '23 at 21:02
  • Do you have a sample input that fails? I've run your code in a loop for every value from 1 to 50. It produces a correct answer in every case (except for the multiples of 5). I'm looking at the table right now. – Tim Roberts Aug 24 '23 at 21:04
  • Test suite Wrong answer 4 / 100 12 ms 11 ms 6,412 KiB – FIma Dev Aug 24 '23 at 21:06
  • Here try running the code on the site, it will give you 4 out of 100 correct answers. And I don't have access to the testing – FIma Dev Aug 24 '23 at 21:07
  • Apparently, they are lying. They said "it is guaranteed that an answer exists", but they are trying all the multiples of 5. There are NO numbers consisting entirely of 1s and 2s that are divisible by 10. The web site appears to be garbage. I've sent feedback. – Tim Roberts Aug 24 '23 at 21:30
  • I just contacted them. It's a typo on the web site. The criteria is not "multiple of 2n", it is "multiple of 2^n". So, your code no longer blows up for multiples of 5, but you are now running into a time limit at n==25. You need a different strategy. – Tim Roberts Aug 24 '23 at 21:51
  • Thank you all, I've found a solution – FIma Dev Aug 24 '23 at 22:02

0 Answers0