1. 程式人生 > 其它 >Yarn【label-based scheduling】實戰總結(一)

Yarn【label-based scheduling】實戰總結(一)

1.安裝gmp

 

2. 基於GMP的大數庫編寫測試程式碼測試大數運算,計算2的N次方,N為你學號的後四位(5‘)

#include "stdio.h" //hello world 工程預設的,如果你建立的是空工程就不需要這句


#include "gmp.h"//記得引入GMP.H的標頭檔案


int main(int argc, char* argv[])


{


mpz_t t; //mpz_t 為GMP內建大數型別


mpz_init(t); //大數t使用前要進行初始化,以便動態分配空間


mpz_ui_pow_ui(t, 2, 1232); //GMP所有函式基本都是以mpz打頭


gmp_printf(
"2^1232=%Zd\n", t); //輸出大數,大數的格式化標誌為%Zd mpz_clear(t); return 0; }

 

3. 基於GMP的大數庫計算你以及前面5位同學和後面5位同學的8位學號的乘積,N為你學號的後四位(5‘)

#include<stdio.h>
#include<string.h>
#include<gmp.h>

int main(){
    mpz_t i,s,o;
    mpz_init_set_str(i,"1",10);
    mpz_init_set_str(s,"20191232",10);
    mpz_init_set_str(o,
"1",10); int p; for(p=0;p<10;p++){ mpz_mul(i,i,s); mpz_add(s,s,o); } gmp_printf("%Zd\n",i); mpz_clear(i); mpz_clear(s); mpz_clear(o); return 0; }