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

Общий форум

1110
Послано Fadeev.E.V 3 янв 2011 04:53
Help please 2 days I suffer over this program, I can not understand that in any way that the checking system wants from me, nevertheless is correct at me deduces, bosh any. Prompt what not so. I have already got confused for 2 days.
_________________________________________________
FUNCTION Power(Osnovanie:Integer;  Stepen:Integer) :Integer;
VAR
i,a:Integer;
BEGIN
a:=1;
for i:=1 to Stepen do a:=a*Osnovanie;
Power:=a;
END;
VAR N,M,Y,i,f,j,r,q,j1:Integer;
x:array[0..9999-1] of integer;
BEGIN
f:=0;
Read(N,M,Y);
for i:=0 to M-1 do
if (power(i,n)) mod M = Y then begin
 f:=1;
 for j:=0 to M-1 do
 x[j]:=i;
 for j:=0 to M-1 do
 for j1:=j+1 to M-1 do
 if x[j]>=x[j1] then
begin
r:=x[j]; x[j]:=x[j1]; x[j1]:=r
end;
Write(x[j]:2);
 end;
if f =0 then Write('-1');
END.
________________________________________________________
Re: 1110
Послано Fadeev.E.V 3 янв 2011 05:10
This is the last my topic.
Re: 1110
Послано Alexey Dergunov [Samara SAU] 3 янв 2011 14:40
Re: 1110
Послано Fadeev.E.V 3 янв 2011 19:10
Thanks, has written on *java*, but jumps out crash. Tell please because of what it can be?
__________________________________________________
import java.io.*;
  class Clas {
static int binpow (int a, int n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return binpow (a, n-1) * a;
    else {
        int b = binpow (a, n/2);
        return b * b;
    }
  }
}

  public class Cl {
    public static void main(String arqs[])
    throws IOException {
        int M,Y,N,f,r,q;
        String m ,y ,n;
        f = 0;
        int x[] = new int[1000-1];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = br.readLine();
        m = br.readLine();
        y = br.readLine();
        N = Integer.parseInt(n);
        M = Integer.parseInt(m);
        Y = Integer.parseInt(y);
        for (int i = 0; i<=M-1; i++)
            if(Clas.binpow(i,N) % M == Y) {
             f=1;
             for (int j = 0; j<=M-1; j++)
                 x[j]=i;
                for (int j = 0; j<=M-1; j++) {
              for (int j1 = j+1; j1<=M-1; j1++)
                     if (x[j]>=x[j1]) {  r=x[j]; x[j]=x[j1]; x[j1]=r;   }
              System.out.print(x[j]+" ");
              }
        if (f == 0) System.out.println("-1");
     }
  }
}

_________________________________________________________
Re: 1110
Послано Fadeev.E.V 3 янв 2011 20:27
Help please last time
Re: 1110
Послано Alexey Dergunov [Samara SAU] 3 янв 2011 20:35
There is an overflow (999^999 in int).
You should use that (a*b)%n == ((a%n)*(b%n))%n.

Edited by author 03.01.2011 20:36
Re: 1110
Послано Fadeev.E.V 3 янв 2011 21:06
Thanks.And it should where be inserted into my code tell please?
Re: 1110
Послано Fadeev.E.V 4 янв 2011 03:15
don't go out.
Re: 1110
Послано Fadeev.E.V 4 янв 2011 03:16
don't go out.
Re: 1110
Послано Fadeev.E.V 4 янв 2011 20:02
Well please prompt as to make, something does not leave at all. Here so can?
_______________________________________________________
import java.io.*;
  class Clas {
 int binpow (int a, int n) {
     int b;
    if (n == 0)
        return 1;
    if (n % 2 == 1)
    return binpow (a, n-1) * a;
    else {
         b = binpow ((a*b)%n, ((a%n)*(b%n))%n);
        return b * b;
    }
  }
}
_______________________________________________________

Edited by author 04.01.2011 20:03

Edited by author 04.01.2011 20:03
Re: 1110
Послано Alexey Dergunov [Samara SAU] 4 янв 2011 21:29
Try to think by yourself. Otherwise you won't get any experience in programming. I've said everything that is needed to solve it. Or do you think I'll post AC code here?
Re: 1110
Послано Fadeev.E.V 4 янв 2011 21:49
I cannot simply understand where it is necessary to insert this expression *_ ((a*b)%n == ((a%n)*(b%n))%n.)_*.Already all rearranged, does not leave, help please last time, fairly I speak I will not write more.
Re: 1110
Послано Fadeev.E.V 5 янв 2011 15:03
Alexey Dergunov [Samara SAU], help me please.