This commit is contained in:
Michał Krzysztof Feiler 2019-01-23 19:13:19 +01:00
parent d7fed67040
commit 383645da81
No known key found for this signature in database
GPG Key ID: E35C2D7C2C6AC724
3 changed files with 150 additions and 0 deletions

73
asdzes2zad1eratostenes/.gitignore vendored Normal file
View File

@ -0,0 +1,73 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

View File

@ -0,0 +1,7 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.c

View File

@ -0,0 +1,70 @@
#include <math.h>
#include <stdio.h>
#pragma pack(push, 1)
#define N 100
struct bool_store {
int v : 1;
};
static struct bool_store _a[N - 1];
#pragma pack(pop)
int A_bf2_get(int i)
{
if (i < 2)
return 0;
return _a[i - 2].v;
}
void A_bf2_set(int i, int b)
{
_a[i - 2].v = b;
}
#define TRUE 1
#define FALSE 0
void doSE()
{
int i;
for (i = 2; i <= N; i++)
A_bf2_set(i, 1);
for (i = 2; i <= sqrt(N); i++)
if (A_bf2_get(i)) {
int j;
for (j = i * i; j <= N; j += i)
A_bf2_set(j, FALSE);
}
}
#define FILL_CHAR '-'
int main()
{
doSE();
int i;
for (i = 0; i <= N; i++) {
if (i % 10 == 0)
putchar('\n');
putchar(' ');
if (A_bf2_get(i))
printf(" %2d", i);
else {
if (i >= 100)
putchar(FILL_CHAR);
else
putchar(' ');
if (i >= 10)
putchar(FILL_CHAR);
else
putchar(' ');
putchar(FILL_CHAR);
}
}
putchar('\n');
return 0;
}