ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1023. Buttons

WA#6
Posted by VorobeY1326 10 Nov 2009 19:51
Help somebody!!
Why my code has WA6..or GIVE SOME TESTS, please))

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

vector<int>easy_numbers(0);

int next_number(int numb_of_numb)
{
        int step=easy_numbers.size()-1;
        int curr_number=easy_numbers[step];
        while(step+1<numb_of_numb)
        {
                while(1)
                {
                        curr_number++;
                        int sq_root=sqrt(static_cast<double>(curr_number))+1;
                        int buf_step;
                        buf_step=0;
                        while(easy_numbers[buf_step]<sq_root)
                                if (curr_number%easy_numbers[buf_step++]!=0) continue;
                                else goto g1;
                        break;
                        g1:
                }
                easy_numbers.push_back(curr_number);
                step++;
        }
        return curr_number;
}

int main()
{
        int K;
        int L=-1;
        cin >> K;
        if (K==4) {cout << 3; exit(0);}
        easy_numbers.push_back(3);
        int buf=0;
        while((easy_numbers[buf]*easy_numbers[buf])<=K)
        next_number(++buf);
        for (int i=0;i<easy_numbers.size();i++)
        {
                if (K%easy_numbers[i]==0) {L=easy_numbers[i]-1; break;}

        }
        if (L==-1 && K%2==0) {L=K/2-1; cout << L;
        exit(0);}
        if (L==-1) {L=K-1; cout << L;
        exit(0);}
        cout << L;
        return 0;
}