随笔分类 - 数论
摘要:1 #include<stdio.h> 2 #include<iostream> 3 #include<math.h> 4 using namespace std; 5 typedef __int64 ll; 6 int main() 7 { 8 int t,ans; 9 scanf("%d",&t);10 int n;11 ll locb,loca;12 while(t--)13 {14 scanf("%d",&n);15 locb = ceil(sqrt(2*(double)n+0.25)-0.5)
阅读全文
摘要:#include<stdio.h>#include<string.h>const int mod = 9973;#define maxn 15struct matrix{ int arr[maxn][maxn];};matrix mul(struct matrix a,struct matrix b,int n){ int i,j,k,temp; struct matrix val; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { for(k=1,temp=0;k<=n;k++) ...
阅读全文
摘要:#include<stdio.h>#include<math.h>#define PI 3.1415926535898#define e 2.7182818284590 int main(){int t,n;double ans;scanf("%d",&t);while(t--){scanf("%d",&n);ans=log10(sqrt(2*PI*n))+n*log10(n/e);printf("%.0lf\n",ceil(ans));}return 0;}
阅读全文
摘要:一般涉及矩阵求幂的问题都要求很大的幂,需要快速求出,这就使人想到了二分法。想到二分法后,首先想到递归:____ DFS(int a){ ____ ret1; if(a==1) return G2; ret1=DFS(a/2); ret1=Cheng(ret1,ret1); if(a%2)ret1=Cheng(ret1,G2); return ret1;}注:____是矩阵结构体的类型,Cheng代表两个矩阵相乘返回的值,DFS函数调用时参数a即为要乘的次数但是递归毕竟是有函数调用的时间,所以不是很快,于是我们就可以用迭代写出更快的程序:matrix pow(...
阅读全文
摘要:1 //表示用到了gcd,本身没什么好说的 2 #include<stdio.h> 3 __int64 gcd(__int64 a,__int64 b) 4 { 5 if(b==0) 6 return a; 7 return gcd(b,a%b); 8 } 9 int main() 10 {11 __int64 t,a,b,c,d;12 __int64 x,y,z;13 __int64 i;14 scanf("%I64d",&t);15 while(t--)16 {17 scanf("%I64d%...
阅读全文
浙公网安备 33010602011771号