Facebook
From Scribby Agouti, 3 Years ago, written in Plain Text.
">

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

from

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

- view diff
Embed
Download Paste or View Raw
Hits: 49
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10. void asalCarp(int x, int factorial)
  11. {
  12.     int original =x;
  13.  
  14.  
  15.  
  16.  
  17.     double sq =sqrt(original);
  18.     if(x<factorial )
  19.         {
  20.             cout << original << " divides " << factorial << "!" << endl;
  21.             return;
  22.         }
  23.     for(int i=2;i<=x;i++) {
  24.  
  25.         if(i>sq && x==original )
  26.         {
  27.             cout << original << " does not divide " << factorial << "!" << endl;
  28.             return;
  29.         }
  30.        
  31.  
  32.         if(x==1) break;
  33.         bool exists = false;
  34.         int howMany = 0;
  35.         while (x % i == 0) {
  36.             exists = true;
  37.             x = x / i;
  38.             howMany++;
  39.  
  40.         }
  41.         if (exists) {
  42.  
  43.             if(i*howMany>factorial)
  44.             {
  45.                 cout << original << " does not divide " << factorial << "!" << endl;
  46.                 return;
  47.             }
  48.         }
  49.  
  50.     }
  51.     cout << original << " divides " << factorial << "!" << endl;
  52.     return;
  53.  
  54. }
  55.  
  56. int main() {
  57.     int factorial, div;
  58.  
  59.     while(cin>>factorial) {
  60.  
  61.         cin >> div;
  62.        asalCarp(div,factorial);
  63.     }
  64.     return 0;
  65. }
  66.