C algorithm problem, please point out with high fingers,

Updated on technology 2024-05-13
7 answers
  1. Anonymous users2024-02-10

    #include""It's the same as yours!

  2. Anonymous users2024-02-09

    The above is roughly correct, the multiplication symbol is wrong, hehe.

  3. Anonymous users2024-02-08

    C++ Algorithm Questions:

    According to the meaning of the title, n<=2*10 9

    In the red box, **i*j in the figure may exceed this range, resulting in the maximum overflow of integers not getting the correct result. It should be changed to a for loop, starting with the largest number and searching for the smaller number, not multiplication, but division.

    for(int i = n-1; n >=sqrt(n); i--)if(n%i==0)

    maxnum= i;

    break;

    Of course, these must ensure that the input n must be satisfied, and only the multiplication of two prime numbers equals n, otherwise it is necessary to increase the judgment whether it is a prime number.

  4. Anonymous users2024-02-07

    Your ** complexity is too high.

    Roughly estimated, o(sqrt(n)*n).

    n data range [0,10 9], definitely timed out.

    In general programming problems, the algorithm with a data range of more than 10 6, o(n) may time out.

    I wrote a slightly faster one, with a complexity of about o(sqrt(n)*sqrt(i)), which should be less than o(n) you try.

    #include

    using namespace std;

    bool isp(int x)

    for(int i=2;i*i<=x;i++)return true;

    int main()

    return 0;

  5. Anonymous users2024-02-06

    It's not that there is no output, it's that the efficiency of this algorithm is relatively low, the amount of calculation is too large, as long as you are willing to wait, the result will still be produced, but the time of this waiting will be larger with the number, the longer the time will be.

    I've changed my mind, and the time will be significantly shortened. Let's experience it for yourself below.

    =The following is ** ==

    One of the test files failed like this: input 1999520027, output 99991 but after I input the 1999520027, there is no output result? Don't know why?

    #include

    #include

    #include

    #include

    using namespace std;

    vector array_a,array_b;

    int isprime(int n)

    if(bit_sum % 3)

    coutreturn 0;

  6. Anonymous users2024-02-05

    Obviously, the macro define base3 (base2+(rate*(break3-break2))) is correct. define base3 (base1+base2+(rate3*(break3-break2))) is a macro that actually adds base1 twice, which doesn't make sense from any point of view.

  7. Anonymous users2024-02-04

    The third picture is correct. In the second diagram, the 360kWh fee for the first level is double-counted (because this fee is already included in base2).

Related questions
8 answers2024-05-13

Do efgh 4 flashing graphs and put them in the corresponding position, and then all these 4 mc visible=false; >>>More

6 answers2024-05-13

If AMD is not a black box, it doesn't need to be super, it can't be super.

11 answers2024-05-13

In addition to love, there are also practical problems, not that love is necessarily together, are you still studying or working now?

9 answers2024-05-13

Oh.. This problem may be caused by your monitor's refresh rate being too high! You can try to boot the computer and press F8 to enter safe mode, press the mouse on the empty space on the desktop and click on the properties, after the window showing the properties appears, there is a column menu on it, and the menu has "Theme", "Desktop", "Screen Saver". >>>More

23 answers2024-05-13

Hello: The beast is just a symbol of a person's identity, don't deliberately pursue the beast! No, if it's not good, it's better to use a better green method yourself, if you're really rich, you can buy one, about 1,000RMB, (it's best to buy WY, don't trade with the finished family, don't be fooled!) )