You are not logged in. Please login at www.codechef.com to post your questions!

×

MULDIG for partial points

0
1

Can someone please explain the subtask 1 for muldig. I made a function which multiply on the basis of indexes. So at (0,0) lies 0x0 at (0,1) lies 0x1 and so on..I was able to find 7,8,10 column which are B+4,B+5,B+7 but how to find the 9th column. Because when we calculate 9th column problem is, when we multiply two digit number say 01 and 10 to find the 9th column that is B+6 we have to add two bits ,here (B+4)(B+7)+(B+5)(B+6) but my function only do multiplication so this is the problem that i can do only (B+4)*(B+7) not addition further. I know editorials will be there but i really want to know what i am missing for 20 points subtask. Please Help Thanks.

asked 17 Jul, 15:17

vishesh_345's gravatar image

4★vishesh_345
1906
accept rate: 6%

edited 17 Jul, 15:18


Here is very short editorial for 100 points:

We do our main calculation using boolean logic. We select a NAND or NOR if our inputs are 0 or 1. A combination of NAND or NOR gates can be used for any boolean function. We can build a small ROM or even a binary multiplier using these gates.

So how do we convert between base 3, 5,7 and binary? If our second input is 0 or 1, we just continue to do NAND or NOR and consider values bigger than 1 on the first input as 1. If the second input is 2, we just do (first input+1) % base. With this function we can easily convert the input into a 1-hot coded binary representation. To convert binary back to base 3,5,7, we can also use this cycling functionality.

link

answered 17 Jul, 15:44

nanoalpaca's gravatar image

6★nanoalpaca
22613
accept rate: 7%

So you are converting the input into binary and multiplying? That's so simple... why didn't I think of this :/
I looked up and found a universal gate in ternary logic which I used to get 40 points, but I was unable to do the same in 5-ary or 7-ary logic due to the huge function space.

(17 Jul, 16:17) meooow6★
1

I'm not even really multiplying. That can be done, but I did not want to write a digital logic synthesis tool for this task. I just calculated a table and used a PLA like structure with an AND and a OR plane to lookup the result. After all up to 100k gate were allowed, so nothing remotely effective was needed. My solution required 37k gates for base 7. (1.5k for base 3, 10k for base 5, 217k for base 11) https://www.codechef.com/viewsolution/14464079

(17 Jul, 17:01) nanoalpaca6★

I'll go through your solution and understand it, thanks!

(17 Jul, 17:07) meooow6★

For just 20 points: see my code

link

answered 17 Jul, 15:23

prakhariitd's gravatar image

6★prakhariitd
1.1k19
accept rate: 10%

Actually for subtask one I used same matrix..

0 0 1

0 1 2

1 2 2

Now If you see right upper 2x2 matrix, It will give addition between every possible pair that can be formed from 0 and 1, But to use this we will have to shift one digit by 1 which we want to add and bottom row 1 2 2 will help in it..

I am not sure if I was clear but Here is my solution for partial subTask of 20 points:

0 0 1

0 1 2

1 2 2

6

4 6 10

3 5 8

4 5 11

3 6 12

2 12 13

11 13 9

Here first two steps are pretty clear, and in 11 and 12 I am temporarily storing multiplication, and using 2 12 13 to shift digit stored in 12, Then using above top right matrix to digits in 11 and 13 and put it in 9.

Obviously this will not help in other tasks, And I could not build proper answer so I am also waiting for tutorial for perfect answer to solve this..

link

answered 17 Jul, 15:28

kauts_kanu's gravatar image

5★kauts_kanu
5797
accept rate: 19%

Yes, This is clear by the example. Thank you.

(17 Jul, 15:52) vishesh_3454★

I guess element(2,2) in matrix 3x3(o based indexing) need not be 2 because it is not used anywhere there will be no query of the form (2,2) until we are on first subtask. I really feel bad for not thinking about this solution. Was very close to this :(. Thanks again.

(17 Jul, 16:42) vishesh_3454★

yup.. there was no use of 2,2.. I just assigned random value there.. :)

(17 Jul, 16:54) kauts_kanu5★

I think you may find my solution interesting because it solves the task within the operation limit even for base 30, and uses a function that's easy to describe:

$f(a,b)=\begin{cases}a&\quad\text{if }b \ne 0\\a - 1\text{ mod }B&\quad\text{if }b = 0\end{cases}$

This function has some useful properties that make it easy to define further building blocks, for example:

  • You can define identity: $id(n) = f(n,1)=n$.
  • You can define decrementation: $dec(n) = f(n,0)=n - 1 \text{ mod } B$.
  • By repeated decrementation you can also define incrementation.
  • You can define logical negation (sort of): $not(n) = f(0,n)=\begin{cases}0&\quad\text{if }b \ne 0\\B - 1&\quad\text{if }b = 0\end{cases}$.
  • You can define a function that decrements the input only if it is nonzero: $f(n, not(n))$. This is useful because it lets you create loops of a sort (a variable may gradually go to zero and once it reaches it, it stays there). So with this function you may repeat incrementation a certain number of times, i.e. perform addition. And then addition a certain number of times to perform multiplication.

I'm sure that there are even more efficient choices than this. It was a fun exercise to see what you can define in terms of such a simple function and I highly recommend trying it on your own.

link

answered 17 Jul, 19:43

sir_ementaler's gravatar image

4★sir_ementaler
533
accept rate: 0%

@sir_ementaler I use another function $$ f(a, b) = \max\{a, b\}+1 \bmod B, $$ and the main idea seems the same to you. However, my approach might be a little complicated.

link

answered 17 Jul, 20:21

liouzhou_101's gravatar image

7★liouzhou_101 ♦♦
291228
accept rate: 0%

I've posted the detailed explanation of the approach here: MULDIG - Editorial (Unofficial)

link

answered 21 Jul, 15:19

lboris's gravatar image

6★lboris
2664
accept rate: 20%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×849
×297

question asked: 17 Jul, 15:17

question was seen: 323 times

last updated: 21 Jul, 15:19