D18992: Kbruch exercise mode improvement

Christoph Feck noreply at phabricator.kde.org
Thu Feb 14 03:08:26 GMT 2019


cfeck added a comment.


  Here is what I use:
  
     /**
      * All primes that fit into 8 bits
      *
      */
     const unsigned char primesTable8[54] = {
           2,   3,   5,   7,  11,  13,  17,  19,  23,
          29,  31,  37,  41,  43,  47,  53,  59,  61,
          67,  71,  73,  79,  83,  89,  97, 101, 103,
         107, 109, 113, 127, 131, 137, 139, 149, 151,
         157, 163, 167, 173, 179, 181, 191, 193, 197,
         199, 211, 223, 227, 229, 233, 239, 241, 251
     };
    
     bool hasTwoHardPrimes(int f)
     {
         for (int j = 0; j < 3; ++j) {
             int p = primesTable8[j];
             while (f % p == 0) {
                 f /= p;
             }
         }
         int pp = 1;
         for (int j = 3; j < 54; ++j) {
             int p = primesTable8[j];
             if (f % p == 0) {
                 f /= p;
                 pp *= p;
            }
        }
        return (pp > 90 || f > 90);
    }
    
     int main(int argc, char *argv[])
     {
         // 6 ... 16
         int level = 10;
         for (int i = 2; i <= 1 << level; ++i) {
             if (isPrime(i) && i < 100 || !hasTwoHardPrimes(i)) {
                 printf("%d, ", i);
             }
         }
         printf("\n");
     }
  
  if `hasTwoHardPrimes()` returns `true`, then I don't show the number for a factorization exercise. Note that this only works for numbers up to about 62500, but a 6th grader can/should factorize even large numbers such as 44100.
  
  Feel free to update your table with numbers checked against this if you agree.

REVISION DETAIL
  https://phabricator.kde.org/D18992

To: khanaasif, #kde_edu
Cc: cfeck, narvaez, apol
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-edu/attachments/20190214/526676e6/attachment.html>


More information about the kde-edu mailing list