Recognizing Useful Prime Numbers

It is useful to recognize prime numbers, especially those between 1-100. Knowing them helps you to efficiently tackle many mathematics problems involving factorization, highest/greatest common factor, lowest common multiple, divisibility test, expression simplification, modulo arithmetic, Diophantine equation, etc.

How do you memorize or recognize prime numbers from 1-1000? Here are some tricks (for human brains!) I found out. Tell me if you have better methods (for human brains but not for computers!).

Level 1: Prime Numbers within 1-10

It is pretty easy to memorize the only 4 prime numbers here: 2, 3, 5, 7. You MUST know them well!

Level 2: Prime Numbers within 11-100

A few facts that you should know before you proceed further:

  • There are exactly 25 prime numbers within 1-100.
  • A number is divisible by 2 if and only if its last digit is even (0, 2, 4, 6, or 8).
  • A number is divisible by 3 if and only if the sum of its digits is divisible by 3.
  • A number is divisible by 5 if and only if its last digit is either 0 or 5.
  • If a number N is not a prime number, then it must be divisible by a prime number that is less than or equal to the square root of N.

So, to check whether a number is prime within 11-100:

  1. If a number does NOT end with 1, 3, 7, or 9, then it is definitely NOT a prime number. This tackles all numbers that are divisible by 2 or 5.
  2. Sum up its digits to check if it is divisible by 3.
  3. Check if the number is divisible by 7. You should have memorized the multiplication table up to either 10x10 or 12x12. So, if the number is less than 70, you can check quickly whether it can be produced with 7 times some integer. If the number is more than 70 (but less than 100), first minus it by 70, and then check as mentioned above. For example, take 97. Minus it by 70, we get 27, in which you can't get it using 7 times some integer. So 97 is not divisible by 7. A few tests do exist for divisibility by 7, but I find them less efficient when dealing with numbers less than 100. Anyway, you are encouraged to learn more about divisibility rules.

This is the list of all 21 prime numbers within 11-100:

11 13 17 19
   23 29   
31       37
41 43 47   
   53    59
61    67   
71 73    79
   83    89
      97   

I have purposely arranged these numbers as shown so that you may see some patterns to help you memorizing them. Memorize them if you can!

Level 3: Prime Numbers within 101-1000

This is getting tough! You can stop here after memorizing all 25 prime numbers that are less than 100.

However, if you are really keen, you may be interested to know a few things:

  • There are exactly 168 prime numbers within 1-1000.
  • To save your effort, first estimate the square root of the given number to find out what divisibility tests you need to use. For example, to check for a number which is less than 400, you only need to try to divide it by the prime numbers up to 20, which is the square root of 400.
  • It helps to learn more about various divisibility rules.

Here's the list of all prime numbers within 1-1000:

  • 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 257 263 269 271 277 281 283 293
  • 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397
  • 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499
  • 503 509 521 523 541 547 557 563 569 571 577 587 593 599
  • 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691
  • 701 709 719 727 733 739 743 751 757 761 769 773 787 797
  • 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887
  • 907 911 919 929 937 941 947 953 967 971 977 983 991 997

If you are a geek who can memorize at least the first 100 decimal digits of pi, then you can try to memorize these numbers too!

Level 4: Prime Number more than 1000

Hmm... guess you better leave it to the computers...

LaTeX and Eclipse on Ubuntu

You are a Ubuntu user who wants the use LaTeX2e and miss your Eclipse 3.6 (Helio), what should you do?

Install LaTeX2e

You must at least install the texlive package to have a working LaTeX in Ubuntu.

You may optionally consider installing these packages too:

  • texlive-full. This installs all the packages in the TeX Live distribution. You need extra nearly 1.5GB to hold all of them!
  • latex-beamer. Excellent for creating presentations.
  • texpower. Excellent for creating dynamic online presentations.
  • texlive-fonts-extra. A large collection of font packages.
  • texlive-latex-extra. A large collection of add-on packages for LaTeX.

Install Eclipse

As of this writing, the latest version of Eclipse package included in the official Ubuntu repositories is 3.5.x (Galileo). If you want to use the latest Eclipse 3.6.x (Helio), then

  1. Visit http://www.eclipse.org/ and grab the latest version of Eclipse, which would be in .tar.gz format. Grab a package variant that suits you most.
  2. Extract the package to a folder, say your home directory or your Desktop.
  3. Create a shortcut on your desktop or your gnome panel to the 'eclipse' executable, using the 'icon.xpm' icon. There you go!

To add LaTeX support to the Eclipse IDE, you can use the TeXlipse plugin.

  1. Open Eclipse.
  2. Select Help > Install New Software....
  3. Click Add..., and fill in the Name and Location fields with TeXlipse and http://texlipse.sourceforge.net respectively. Click OK. Eclipse should then visit the repository to fetch the software available.
  4. Select TeXlipse, click Next, read and accept the license agreement, click Finish, and wait for the installation to complete. Restart Eclipse for the plug-in to take effect.

A few more tips:

  • While in Eclipse, select Window > Preferences > Texlipse > Viewer Settings. Remove the entry 'none ()' (Why is it there?). You can create a new PDF viewer by filling the fields 'Viewer name', 'Viewer command', and 'Viewer arguments' with 'evince', '/usr/bin/evince', and '%file' respectively. Add or remove other viewers to suit your usage.
  • Official User Manual of TeXlipse. It is good to spend a few minutes to read through the 'Editor features' section.
  • Problem configuring out how to write some symbols in LaTeX? Consult Detexify2!

Schedule Jobs in Ubuntu (and Other Major GNU/Linux distros)

In Ubuntu, how do you schedule some jobs (shell commands) to be executed in the future? You can use at.

Add a Scheduled Job

Run a terminal emulator. Change to the directory where you want to run the command, and issue:

$ at time_specification

The time specification can be rather sophisticated. You can specify HH:MM (e.g., 15:30), midnight, noon, teatime (4pm), month-day day (e.g., Dec 15), time + days (e.g., 4pm + 3 days, to run a job at 4pm three days from now), time + date (e.g., 10am tomorrow), etc. Don't worry that it will misunderstand your schedule as you can (and should) verify it later.

How to Disable the Suspend Button in Ubuntu (10.10)?

I am using Ubuntu on a desktop and I don't want my box to go sleeping when I press the suspend button accidentally. Furthermore, I want to reassign the button to do something more useful. How should I do it?

If you open System -> Preferences -> Power Management and click the General tab, you can configure the action when the button is pressed. However, you can only choose the action to be either 'Suspend' or 'Hibernate', and can't make it to do nothing!

To force it to do nothing, press Alt+F2, enter gconf-editor to invoke the Configuration Editor. Navigate to /apps/gnome-power-manager/buttons, click the value field of suspend, and enter 'nothing' (Enter this 7-character string, not enter nothing!). Close it and you are done! Press your suspend button now to confirm that it really will not suspend your box.

If you mind to check it out further, open System -> Preferences -> Power Management and you will find that the related action is magically set to "Do nothing". If you want to assign a keyboard shortcut for the button now, do it by opening System -> Preferences -> Keyboard Shortcuts.

Time Taken to Move an Ext4 Partition

My harddisk was running out of storage space. Or to be more precise, my /home partition was short of space. I wanted to squeeze a bit more space but was lazy to examine what existing files I can delete. So I took an 'easy' way out: Used gparted to shrink other partitions to make way for the /home partition!

I had overestimated the bulkiness of GNU/Linux and had initially allocated 40GB for the root partition /. But in reality, I hardly use more than 10GB from this partition. So I decided to shrink this partition to become only 20GB. I headed to GParted [gparted.sourceforge.net] to download its latest stable image to make a live USB. (Warning: Backup your extremely important data before you use this!) It is very easy to use GParted. My concern was that what I was doing involve a very expensive operation: Move the beginning of my /home partition, where about 500GB had been occupied. There doesn't seem to have an implementation that can do this in a short amount of time. (Or is it that the structure of an ext4 filesystem that fundamentally prevents one from doing this?) (In contrast, it generally takes a few seconds to move the end of an ext4 partition.)

I wanted to expand my /home partition by hook or by crook, although I had no idea how long gparted would take. I had my answer soon after I booted from the live USB and started gparted: 10 hours! In particular, gparted used two hours plus to test reading all data from the partition, and used seven hours plus to move the data after that! No choice, so I left my computer to gparted overnight, and prayed hard that there would not be any power interruption! (Of course, I had made a backup of very important data to another harddisk.)

Anyway, I deserve what I want now after 10 hours of waiting and sleeping:

天树征丸的《金田一少年之事件簿:黑魔术杀人事件》

看了《金田一少年之事件簿:剑持警部杀人事件》后,本想先解决埃勒里·奎恩(Ellery Queen)的《荷兰鞋子的秘密》(The Dutch Shoe Mystery),但无意中发现我与我弟弟这几年来买了几本金田一的漫画,但有些还没看过。想了想,解决金田一的事件较为轻松,所以就先试一试他的事件吧。刚看完了《黑魔术杀人事件》,个人评价如下:

  • 解谜合理度:还算合理。上网查了一下,有人觉得第二宗命案的手法不太实际,但我觉得还可接受。毕竟凶手有很充裕的时间布置命案现场,所以还是行得通的。
  • 线索足够度(所给线索足以指出真凶及干案手法吗?):要找出凶手是没问题,因为至少有一个决定性的证据能指出唯一可能的凶手。然而对于第二宗命案,真要争议的话我觉得其实还可解出其他的干案手法。(而在本格派大师如埃勒里·奎恩的作品中,你会有更足够的线索可让你仔细地排除其他一切可能的手法而找出唯一解。)而且书中对某个重要的线索似乎没交代清楚。(详情请读下一段落。)无论如何至少你找到了凶手后就基本上破案了。
  • 解谜难度:30分。每个命案设定得还可以。作者把一个很决定性的证据隐藏得还好,但观察力强的读者应能找出来。然而解决金田一的案件的关键通常在于寻找那隐藏的线索或证据而直接破案,而通常无需经过较复杂的逻辑思考,所以一般上解谜难度不算大。

我自己的看过一遍后就大概知道其干案手法,但找不出凶手。然后对重要的线索再看过一遍后找到了凶手,可是还找不出第二宗命案的手法。在漫画里,金田一在解决该案时作者有暗示他解决此案的思路并因此破案,我从他的思路中想到了作者应该是想要使用某个还算有名的数学游戏的方法来设计此案,所以解决了此案。然而冤枉的是,不知是原作者没说好,还是我读的中译本翻译得不够精准,在漫画中,要使用该干案手法所需要的某个重要假设或线索并没交代清楚。我在此自言自语也不是办法,所以想知道细节的看官请用滑鼠选择以反白以下文字:(注意!警告!以下文字有透露一些剧情!)要使用该手法,那电灯的电线须钉着地毡但不可钉着地面!我看的翻译只说“看!电灯的软线被钉住了…似乎很早就钉上了…”,但没画上也没说清楚该电线是否也被钉在地上。而我想到的另一个较容易的手法是,凶手其实可在佈置凶案现场时先打开手电筒或另一盏灯,然后再拔掉魔术灯的插头,把电线简单地从地毡下拿出来再从其上面插回插座,再关掉手电筒或另一盏灯,就完成佈置了。如果你看的翻译不一样,或发现我其实遗漏了什么情节或线索,请告诉我。

另外也发现作者写了一个前言不对后语但无关破案的小情节。有一点剧透,所以真要看的话请反白以下文字:高远遥一看到金田一后,有说过连金田一也出现在这里,让他感到有点意外,还无所谓地说观众越多越好;可是解谜后却发现,其实是高远遥一在幕后硬要邀请金田一去的。你同意吗?

想先看完金田一的漫画,所以下一本应该也是金田一的案件。

Rescuing A Hung GNU/Linux System

My GNU/Linux box just hanged. It is actually my own fault as I tried to empty the swap partition (with sudo swapoff -a; sudo swapon -a) without realizing that I don't have enough RAM space! Anyway, if you have a hung X session, what can you do?

Note: I assume that you are using QWERTY keyboard. If not, convert the key sequence as described here [wikipedia.org].

  • Kill the X session. Do this with Ctrl-Alt-Backspace. This should bring you back to the X login window. You can't do this in Ubuntu anymore. If so, kill the processes in the current virtual console as described below.
  • Kill all processes on the current virtual console. Do this with Alt-SysRq-K if you fail to kill the X session as described above. This should bring you back to the X login window.
  • Reboot the system safely. Do this if you fail to reboot the system in the normal ways. To reboot a GNU/Linux system safely, use the following key combinations in sequence:
    1. Alt-SysRq-R. Take the control of the keyboard.
    2. Alt-SysRq-E. Send SIGTERM to all processes.
    3. Alt-SysRq-I. Send SIGKILL to all processes.
    4. Alt-SysRq-S. Sync all mounted filesystems.
    5. Alt-SysRq-U. Remount all filesystems in read-only mode.
    6. Alt-SysRq-B. Reboot!
  • You can memorize this magic sequence with "Reboot Even If System Utterly Broken", or simply "BUSIER" backwards.

  • Press the 'magical' reset button! Frankly speaking, you almost never need to do this with Linux. (Although you may do this very often in some other operating systems.)
Syndicate content