1.大数取余:
对于较大数快速取余
参数:char s[] 为储存大数的数组
modNumber 为MOD
long long modNumber(char * s,int modNumber)
{
long long sum = 0;
for (int i = 0; i < strlen(s); ++i)
{
sum = sum*10 + s[i]-48;
sum %= modNumber;
}
return sum;
}
2.快速幂(极大数)取余:
对于较大数快速取余
参数:a的b次方 对 c 取余
long long PowerMod(long long a, long long b, long long c)
{
long long ans = 1;
a = a % c;
while(b>0)
{
if(b % 2 == 1)
ans = (ans * a) % c;
b = b/2;
a = (a * a) % c;
}
return ans;
}
3.数据类型范围:
unsigned int 0~4294967295
int 2147483648~2147483647
unsigned long 0~4294967295
long 2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:18446744073709551615
__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615
4.cin cout 速度慢问题
ios::sync_with_stdio(false);
5.几个提高速度的优化方案
多个if -> 数组实现