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

×

How to find all possible K values for the given problem?

Given an array of N integers.

a[1]%K = a[2]%K = a[3]%K = .... a[n]%K

1) 1<K<N, 1< N<10^6, 1<a[i]<10^9

2) How will you find all possible values for K?

P.S : No brute force approach.

asked 09 Aug, 19:11

check_me's gravatar image

2★check_me
72
accept rate: 0%


Hint: if $a_1 \text{ mod } K = a_2 \text{ mod } K$, then $(a_1 - a_2) \text{ mod } K = 0$. Therefore $K$ has to be a divisor of $a_1 - a_2$.

link

answered 10 Aug, 03:19

afaxnraner's gravatar image

6★afaxnraner
5665
accept rate: 25%

edited 10 Aug, 03:19

Can you please give some Q link? People need it to verify that this isnt related to an on-going contest. I will be happy to help after that :)

link

answered 09 Aug, 19:52

vijju123's gravatar image

5★vijju123 ♦
9.8k213
accept rate: 18%

It is not related to ongoing contest. Link

(09 Aug, 19:58) check_me2★

Thanks!! :)

(09 Aug, 20:06) vijju123 ♦5★
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:

×870
×777
×528
×259
×56

question asked: 09 Aug, 19:11

question was seen: 148 times

last updated: 10 Aug, 03:19