📄 ciperbasic.cpp
字号:
//CiperLib Demo program
// BY CSK(陈士凯)
// CSK@live.com
// www.csksoft.net
#include "stdafx.h"
#include "../CiperLib/CiperLib.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Integer::Init(409600);
char output[20000];
cout<<"Big Integer Demo APP"<<endl;
cout<<"----------------------------"<<endl;
cout<<"Demo1: Calc 1000!"<<endl;
system("pause");
Integer Base(1000),Ans(1);
while(!Base.isZero())
{
Ans *= Base;
Base -= 1;
}
cout<<"Finished, Press any key to disp ans"<<endl;
system("pause");
Ans.toString(output,20000);
cout<<"Finished, Ans is:"<<endl<<output <<endl;
system("pause");
system("cls");
cout<<"Demo 2: Class Integer Usage"<<endl;
cout<<"----------------------------"<<endl;
cout<<"Supported Features:"<<endl;
cout<<"arbitrary length of integer: "<<endl;
cout<<" Integer::Init(2048); //2048 bit"<<endl;
cout<<"easy evaluate:"<<endl;
cout<<" Integer myInt(22); //from int"<<endl;
cout<<" Integer myInt((__int64)13124141313); //from 64 bit int"<<endl;
cout<<" Integer myInt(\"1124241111\"); //from string"<<endl;
cout<<" Integer myInt = \"1124241111\"; //directly assign"<<endl;
cout<<" myInt = myIntA + (myIntB * myIntC) //directly operation"<<endl;
system("pause");
system("cls");
cout<<"Demo 3: Modular arithmetic"<<endl;
cout<<"----------------------------"<<endl;
ZModn Zm1;
Zm1.setMod(Integer(31));
cout<<"set m = 31 in Zm"<<endl;
Integer A(3),B(23);
cout<<"A = 3, B = 23"<<endl;
cout<<"A + B (mod m)="<<endl;
Ans = A;
Zm1.mod_add(B,Ans);
Ans.toString(output,20000);
cout<<" "<<output<<endl<<endl;
Ans = A;
cout<<"A * B (mod m)="<<endl;
Zm1.mod_mul(B,Ans);
Ans.toString(output,20000);
cout<<" "<<output<<endl<<endl;
Ans = A;
cout<<"A ^ B (mod m)="<<endl;
Zm1.mod_pow(Ans,B);
Ans.toString(output,20000);
cout<<" "<<output<<endl<<endl;
Ans = "55566677";
Ans.toString(output,20000);
cout<<output<<" is ";
cout<<(ZModn::isPrime(Ans)?"":"not ")<<"a prime"<<endl<<endl;
Ans = "342424322354353263224223634534435237373454353463464354432";
ZModn::genPrime(Ans,Ans);
Ans.toString(output,20000);
cout<<"Find a prime:" << output<<endl;
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -