数学问题
一、取模运算的特点:
应用:
数位拆解。
二、进制转换:
三、求最大公约数:
四、最小公倍数:
最小公倍数为两数的乘积除以它们的最大公约数。
五、素数筛法:
1、给定一个数,从2开始,一次增加到n1/2,以此判断是否可以被n整除。(暴力求解)
2、采用素数筛法:
#include<stdio.h> int a[10000]={0}; int main(){ int n; while(scanf("%d",&n)==1){ for(int i=2;i<n;i++){ if(a[i]==0){ for(int j=2;i*j<n;j++){ a[i*j]=1; } } } for(int i=2;i<n;i++){ if(a[i]==0){ printf("%d ",i); } } } }
六、分解素因数:
1、先求出来素数
2、对素数进行遍历判断。
七、二分求幂:
#include<stdio.h> int main(){ int a,b; while(scanf("%d %d",&a,&b)==2){ if(a==0 && b==0) break; int ans=1; while(b!=0){ if(b%2==1){ ans*=a; ans%=1000; } b=b/2; a=a*a; a%=1000; } printf("%d ",ans); } }
八、高精度整数:
1、概念:指有一些整数可能数值非常巨大以至于我们无法用任何内置整数类型来保存它的值,即高精度整数。
2、java中有biginteger类,可以查阅相关资料了解其用法并完成本节练习即可。 biginteger类详解
3、常用下面的结构体来保存个高精度整数:
struct bigInteger{
int digit[1000];
int size;
}
其中digit数组用来保存大整数中若干位的数字,这里使用4为为一个保存单位,size为digit数组中第一个我们还没使用过的数组单元,以整数123456789为例,当我们使用过该结构体来保存该值时,其结果是这样的:digit[0]=6789;digit[1]=2345;digit[2]=1;size=3;