大数相加:
1 string sum(string s1,string s2) { 2 if(s1.length() < s2.length()) {string temp = s1;s1 = s2; s2 = temp;} 3 int i,j; 4 for(i = s1.length() - 1,j = s2.length() - 1;i >= 0;i--,j--){ 5 s1[i] = char(s1[i] + (j >= 0?s2[j] - '0':0)); 6 if(s1[i] - '0' >= 10){ 7 s1[i] = char((s1[i] - '0') % 10 + '0'); 8 if(i) s1[i-1] ++; 9 else s1 = '1' + s1; 10 } 11 } 12 return s1; 13 }
快速相乘
1 ll ksc(l a, ll b, ll mod) //快速乘法 2 { 3 return (a*b-(ll)((long double)a*b/mod)*mod+mod)%mod; 4 }