ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1204. Идемпотенты

And my AC time = 0.968! Can anybody explain to me normal idea of solving this problem?
Послано Ярославцев Григорий 7 апр 2004 19:05
Re: And my AC time = 0.968! Can anybody explain to me normal idea of solving this problem?
Послано buggzy (Ilya Teterin - USU) 7 апр 2004 19:58
Most of the time spent to find prime divisors. Probably you can optimize it. Try to seek with step=2 instead of 1 for example ;)

Edited by author 07.04.2004 20:04
solution
Послано Gheorghe Stefan 7 апр 2004 23:10
Re: solution
Послано Gheorghe Stefan 7 апр 2004 23:11
maybe you can compute the primes with Eratostene's sieve...
Re: And my AC time = 0.968! Can anybody explain to me normal idea of solving this problem?
Послано Ярославцев Григорий 8 апр 2004 14:37
I think not. I think that the main problem is with the algorithm itself. It is just a little bit optimized
O(sqrt(n)). What is the normal way of finding solutions for
|k1*p - k2*q| = 1?  (k1 and k2 should be found).

Edited by author 08.04.2004 14:42
my algo
Послано buggzy (Ilya Teterin - USU) 8 апр 2004 16:26
ap mod bp = cp, c<b, if cp=0 then b=1 and p==gcd(ap, bp)

Recurrent algorithm:

A(1)=p, B(0)=q
C(i)=A(i) mod B(i), A(i+1)=B(i), B(i+1)=C(i)

As gcd(p,q)==1, we get C(i)=1. Then lets write equations sequence:

A(1)-X(1)*B(1)=C(1)
A(2)-X(2)*B(2)=C(2)
...
A(i)-X(i)*B(i)=1

Please note that A(1)==p. Write down coefficient of A(1) in the final equation, and we'll get K such as p*K+q*K2=1. I guess it's the same algorith than called "extended euqlidian" somewhere in this forum.
Re: And my AC time = 0.968! Can anybody explain to me normal idea of solving this problem?
Послано GodZilla 9 апр 2004 20:33
Can you tell me the method of finding
k1 and k2 in

a*k1 + b*k2 = 1, where gcd(a,b)=1 ????

Please, help !!!!!!!!!!
Re: And my AC time = 0.968! Can anybody explain to me normal idea of solving this problem?
Послано Gheorghe Stefan 12 апр 2004 15:43
Euclid extended algorithme for GCD
Re: my algo
Послано MU-OI 20 май 2004 19:27
Thank you very much !!!!!
You way is very good !!!!!