Esempio n. 1
0
File: fctrl2.c Progetto: candu/spoj
struct big* big_mul(struct big* b1, struct big* b2) {
  struct big* car = big_mul_single(b1, b2->x);
  if (!b2->q) {
    return car;
  }
  struct big* cdr = big_new(0);
  cdr->q = big_mul(b1, b2->q);
  return big_add(car, cdr);
}
Esempio n. 2
0
File: 495.c Progetto: doucette/uva
int main()
{
    big f[5001];
    int m = 2, n;

    memset(f, 0, sizeof(f));
    f[1].v[116] = 1;

    while (scanf("%d", &n) == 1) {
        for (; m <= n; ++m)
            big_add(&f[m - 2], &f[m - 1], &f[m]);
        printf("The Fibonacci number for %d is ", n);
        big_print(&f[n]);
        putchar('\n');
    }

    return 0;
}
Esempio n. 3
0
File: acm288.c Progetto: zhouer/ACM
Number pre4() {
	Number result = pre3();
	Number n;
	int type;

	while (accept(TOKEN_ADD) || accept(TOKEN_SUB)) {
		type = token.type;
		get_token();
		n = pre3();

		if (type == TOKEN_SUB) {
			n.sign *= -1;
		}

		result = big_add(result, n);
	}

	return result;
}
Esempio n. 4
0
DWORD big_mul(LPBYTE a, LPBYTE b, DWORD s, LPBYTE out, DWORD out_s)
{
	uint8_t carry = NULL;
	uint8_t sum = NULL;
	uint8_t tsum = NULL;

	uint8_t mod_c = 0;

	BYTE tmp_a[1024] = {};
	BYTE tmp_b[1024] = {};
	BYTE tmp_c[1024] = {};

	uint4* psum = (uint4*)&sum;
	uint8_t* A = (uint8_t*)a;
	uint8_t* B = (uint8_t*)b;
	uint8_t* C = (uint8_t*)out;

	DWORD a_pos = 0;
	DWORD b_pos = 0;

	DWORD A_s = s;
	DWORD B_s = s;
	DWORD C_s = out_s;


	DWORD t_val = 0;
	int i = 0;
	int c = 0;
	int k = 0;

	int place = 2;

	for (int j = A_s; j > 0; j--)
	{
		i = j - 1;
		place = 2;
		
		do
		{
			carry = 0;
			k = 0;
			t_val = ((place == 1) ? ((uint4*)&B[i])->valueb : ((uint4*)&B[i])->value);
			// loop top number
			a_pos = NULL;
			for (int h = B_s; h > 0; h--)
			{
				c = h - 1;

				sum = (((uint4*)&A[c])->value
					*
					t_val)/*((uint4*)&B[i])->value)*/
					+
					carry;

				mod_c = psum->value;

				carry = psum->valueb;

				tsum = mod_c;

				//((uint4*)&tmp_a[k])->value = tsum;
				set_nibble(tmp_a, 32, b_pos + a_pos, ((uint4*)&tsum));
				a_pos++;

				sum = (((uint4*)&A[c])->valueb
					*
					t_val)
					+
					carry;

				mod_c = psum->value;

				carry = psum->valueb;

				tsum = mod_c;

				//((uint4*)&tmp_a[k])->valueb = tsum;

				set_nibble(tmp_a, 32, b_pos + a_pos, ((uint4*)&tsum));

				if (c == 0 && carry)
				{
					//((uint4*)&tmp_a[k + 1])->value = carry;
					set_nibble(tmp_a, 32, (b_pos + a_pos) + 1, ((uint4*)&carry));
					
					k++;

					continue;
				}
				else if (c == 0)
				{
					//break;
				}
				a_pos++;
				k++;
			}

			b_pos++;
			Utils::SwitchOrder(tmp_a, s);

			big_add(tmp_a, tmp_b, s, tmp_c, s);


			memcpy_s(tmp_b, s, tmp_c, s);

			ZERO_(tmp_a, 1024);
			ZERO_(tmp_c, 1024);
			
			place--;

		} while (place > 0);

	}


	memcpy_s(out, out_s, tmp_b, s);
	

	return FALSE;
}