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

Обсуждение задачи 1023. Пуговицы

Показать все сообщения Спрятать все сообщения

what is wrong ? evil 16 апр 2002 11:52
#include <iostream.h>
#include <math.h>
void main()
{   float k;
    long i,l;
cin>>k;
{l=int(k)-1;
for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i-
1;break;};
cout<<l;};
}
always get wrong answer
Re: what is wrong ? LiangHonghao 16 апр 2002 12:21
> #include <iostream.h>
> #include <math.h>
> void main()
> {   float k;
>     long i,l;
> cin>>k;
> {l=int(k)-1;
> for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i-
> 1;break;};
> cout<<l;};
> }
Though I don't know what wrong about
sqrt(k)+4 but
I use k/2 instead of sqrt(k) and Get a AC
try it please .
I haven't learn C++ but I learned C and Pascal
Why don't you use % in you program?
If there is no % in C++ you can try this
(k/i-int(k/i)<1e-15)
and i think you'll get AC then.
At last I give you a AC C program;
#include<math.h>
void main()
{
  long n;
  long i;
  scanf("%ld",&n);
  for (i=3;i<=n/2;i++)
    if (!(n%i))
      {printf("%ld\n",i-1);exit();}
  printf("%ld\n",n-1);
}
Good luck next time.:-)
this is much faster hawking 3 авг 2002 03:18
> > #include <iostream.h>
> > #include <math.h>
> > void main()
> > {   float k;
> >     long i,l;
> > cin>>k;
> > {l=int(k)-1;
> > for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i-
> > 1;break;};
#include<iostream.h>
#include<math.h>
int k,l;
void main()
{
    cin>>k;
    long temp=(long)floor(sqrt(k))+2;//be care about k=4
    for(long i=3;i<=temp;i++)
        if(k%i==0){
            cout<<i-1;
            return;
        }

    if(k%2==0)k/=2;
    cout<<k-1;

}
> > cout<<l;};
> > }
> Though I don't know what wrong about
> sqrt(k)+4 but
> I use k/2 instead of sqrt(k) and Get a AC
> try it please .
> I haven't learn C++ but I learned C and Pascal
> Why don't you use % in you program?
> If there is no % in C++ you can try this
> (k/i-int(k/i)<1e-15)
> and i think you'll get AC then.
> At last I give you a AC C program;
> #include<math.h>
> void main()
> {
>   long n;
>   long i;
>   scanf("%ld",&n);
>   for (i=3;i<=n/2;i++)
>     if (!(n%i))
>       {printf("%ld\n",i-1);exit();}
>   printf("%ld\n",n-1);
> }
> Good luck next time.:-)
>