0

During execution, the algorithm just shuts down (I looked through debug). Condition: The algorithm belongs to the numerical segment [A;B] (1<A<B<1000000) outputs numbers that have exactly three different natural odd divisors among the divisors, not counting 1 and the number itself (if it is odd). For each found number, it outputs in 1 line separated by a space : the number itself and 3 odd divisors. Example: 30 3 5 15 , 42 3 7 21 , 54 3 9 27 , 60 3 5 15 , 66 3 11 33

My code:

#include <iostream>
using namespace std;

int main()
{
    int A,B,g,j,i,c,chislo1,chislo2,chislo3,counter1;
    A=30;
    B=68;
    counter1=0;
    chislo1=0;
    chislo2=0;
    chislo3=0;
    if (1<A && B<1000000)
    {
        for (A;A!=B;A++)
        {
            for (i=2;i!=A+1;i++)
            {
                if (A%i==0 && i&2!=0)
                {
                    counter1+=1;
                }
            }
            if (counter1==3)
            {
                for (i=2;i!=A+1;i++)
                {
                    if (A%i==0 && i%2!=0)
                    {
                        chislo1=i;
                        break;
                    }
                }
                for (i=chislo1+1;i!=A+1;i++)
                {
                    if (A%i==0 && i%2!=0)
                    {
                        chislo2=i;
                        break;
                    }
                }
                for (i=chislo2+1;i!=A+1;i++)
                {
                    if (A%i==0 && i%2!=0)
                    {
                        chislo3=i;
                        cout<<A<<" "<<chislo1<<" "<<chislo2<<" "<<chislo3<<endl;
                        counter1=0;
                        counter1=0;
                        chislo1=0;
                        chislo2=0;
                        chislo3=0;
                        break;
                    }
                }
            }
        }   
    }
    else
    {
        cout<<"Неверный диапазон";
    }
    return 0;
}
Wismut
  • 3
  • 2
  • 1
    *"the algorithm just shuts down"* -- algorithms do not shut down. Perhaps you meant the **program** (the implementation of an algorithm) shuts down? – JaMiT Nov 25 '22 at 21:15
  • 1
    *"I looked through debug"* -- this is good. So you should know more details about the crash. Could you add an indication of which line is the last executed? Including the values of the variables mentioned on that line would also be good. – JaMiT Nov 25 '22 at 21:17
  • When I compiled your code, it gave a few warnings, one of which would probably be of interest to you (possibly in the future; it might be unrelated to your current error). [Why (and how) to enable warnings](https://stackoverflow.com/questions/57842756/why-should-i-always-enable-compiler-warnings). – JaMiT Nov 25 '22 at 21:23

0 Answers0