Esempio n. 1
0
/*
doc:	<routine name="ht_create" return_type="int" export="shared">
doc:		<summary>Initializes a hash-table `ht' to hold `n' items of size `sval'. This is the C equivalent version of the EiffelBase HASH_TABLE class. We allocate the table so that it can hold at least (n + n // 2) entries.</summary>
doc:		<param name="ht" type="struct htable *">Table to initialize.</param>
doc:		<param name="n" type="size_t">Number of elements `ht' must accomodate.</param>
doc:		<param name="sval" type="size_t">Size of elements stored in `ht'.</param>
doc:		<return>Returns 0 if initialization was done, -1 otherwise.</return>
doc:		<thread_safety>Not Safe</thread_safety>
doc:		<synchronization>None</synchronization>
doc:	</routine>
*/
rt_shared int ht_create(struct htable *ht, size_t n, size_t sval)
{
	size_t l_capacity;		/* Size of created table */
	char *array;		/* For array creation (keys/values) */

	REQUIRE("ht not null", ht);
	
	l_capacity = nprime(n + (n / 2));	/* Table's size */

	array = (char *) eif_calloc(l_capacity, sizeof(rt_uint_ptr));	/* Mallocs array of keys */
	if (!array) {
		return -1;					/* Malloc failed */
	}
	ht->h_keys = (rt_uint_ptr *) array;		/* Where array of keys is stored */

	array = (char *) eif_calloc(l_capacity, sizeof(char));
	if (!array) {
		eif_free(ht->h_keys);
		return -1;
	}
	ht->h_deleted = array;

	array = (char *) eif_calloc(l_capacity, sval);			/* Mallocs array of values */
	if (!array) {
		eif_free(ht->h_keys);			/* Free keys array */
		eif_free(ht->h_deleted);
		return -1;					/* Malloc failed */
	}
	ht->h_values = (void *) array;			/* Where array of keys is stored */

	ht->h_capacity = l_capacity;				/* Size of hash table */
	ht->h_sval = sval;				/* Size of each stored item */

	return 0;			/* Creation was ok */
}
Esempio n. 2
0
int main()
{
	int N;
	scanf("%d",&N);
	int total = nprime(N);
	int i;
	if( N % 2 == 0)
		for(i = 0 ; i < total ; i++)
			printf("%d\n",Array2[i]);
	else
		for(i = 0 ; i < total ; i++)
			printf("%d\n",Array1[i]);
	return 0;
}
Esempio n. 3
0
QtGMP::QtGMP(QWidget *parent):QWidget(parent)
{
    QVBoxLayout *vertical = new QVBoxLayout(parent);
    QHBoxLayout *horizon = new QHBoxLayout();
    QGridLayout *grid = new QGridLayout();

    QLabel *label = new QLabel("A:",parent);
    lineEdit1=new QLineEdit("1234567890");
    QLabel *label2 = new QLabel("B:",parent);
    lineEdit2=new QLineEdit("1800");

    QRegExp rx("\\d+");
    QValidator *validator = new QRegExpValidator(rx, this);
    lineEdit1->setValidator(validator);
    lineEdit1->setValidator(validator);

    horizon->addWidget(label);
    horizon->addWidget(lineEdit1);
    horizon->addWidget(label2);
    horizon->addWidget(lineEdit2);
    QPushButton *pushButton1 = new QPushButton("    A*B     ",parent);
    QPushButton *pushButton2 = new QPushButton("    A^B     ",parent);
    QPushButton *pushButton3 = new QPushButton("    B!      " ,parent);
    QPushButton *pushButton4 = new QPushButton("NextPrime(A)",parent);
    QPushButton *pushButton5 = new QPushButton("  GCD(A,B)  ",parent);
    QPushButton *pushButton6 = new QPushButton("  LCM(A,B)  ",parent);

    grid->addWidget(pushButton1,0,0);
    grid->addWidget(pushButton2,0,1);
    grid->addWidget(pushButton5,1,1);
    grid->addWidget(pushButton6,1,0);
    grid->addWidget(pushButton3,2,1);
    grid->addWidget(pushButton4,2,0);

    vertical->addLayout(horizon);
    textEdit= new QTextEdit("hello,bbs.emath.ac.cn.\nThis is Wayne");
    vertical->addWidget(textEdit);
    vertical->addLayout(grid);
    setLayout(vertical);
    connect(pushButton1, SIGNAL(clicked()),this, SLOT(mulAB()));
    connect(pushButton2, SIGNAL(clicked()),this, SLOT(powAB()));
    connect(pushButton3, SIGNAL(clicked()),this, SLOT(fac()));
    connect(pushButton4, SIGNAL(clicked()),this, SLOT(nprime()));
    connect(pushButton5, SIGNAL(clicked()),this, SLOT(gcd()));
    connect(pushButton6, SIGNAL(clicked()),this, SLOT(lcm()));
}
Esempio n. 4
0
int nprime(int N)
{
	if( N == 1)
	{
		Array1[0] = 2;
		Array1[1] = 3;
		Array1[2] = 5;
		Array1[3] = 7;
		return 4;
	}
	int num = nprime(N - 1);
	int total=0;
	int i = 0;
	if(N % 2 == 0){
		for(; i < num ; i++){
			if(test_prime(Array1[i] * 10 + 1))
				Array2[total++] =Array1[i] * 10 + 1;
			if(test_prime(Array1[i] * 10 + 3))
				Array2[total++] =Array1[i] * 10 + 3;
			if(test_prime(Array1[i] * 10 + 7))
				Array2[total++] =Array1[i] * 10 + 7;
			if(test_prime(Array1[i] * 10 + 9))
				Array2[total++] =Array1[i] * 10 + 9;
		}
	}
	else{
		for(; i < num ; i++){
			if(test_prime(Array2[i] * 10 + 1))
				Array1[total++] =Array2[i] * 10 + 1;
			if(test_prime(Array2[i] * 10 + 3))
				Array1[total++] =Array2[i] * 10 + 3;
			if(test_prime(Array2[i] * 10 + 7))
				Array1[total++] =Array2[i] * 10 + 7;
			if(test_prime(Array2[i] * 10 + 9))
				Array1[total++] =Array2[i] * 10 + 9;
		}
	}
	return total;
}