Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- // MA 02110-1301, USA.
- #include <stdio.h>
- //#include <math.h>
- int main()
- {
- int i, t, n, m, r, x, z, a, b, c, d, count, flag, y, l, j, k;
- int ar[100000];
- ar[0] = 2, ar[1] = 3, ar[2] = 5, ar[3] = 7, ar[4] = 11;
- for (j = 5; j < 100000; j++)
- {
- l = j - 1;
- for (k = ar[j - 1] + 2; ; k = k + 2)
- {
- if ( (k % 5 != 0) && (k % 3 != 0) && (k % 7 != 0) )
- {
- y = k / 2;
- for (a = 4; a < l; a++)
- {
- if (ar[a] > y)
- {
- a = l;
- break;
- }
- if (k % ar[a] == 0)
- {
- break;
- }
- else if (a > 1140)
- {
- a = l;
- break;
- }
- }
- if (a == l)
- {
- ar[j] = k;
- break;
- }
- }
- }
- }
- scanf("%d", &t);
- for (i = 1; i <= t; i++)
- {
- scanf("%d", &n);
- printf("prime[%d] = %d\n", n, ar[n - 1]);
- }
- //printf("Hello World\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement