Sum of Squares Theorems

这个在Cryptography里有用,因为对于大的数找起来很难

Legendre's three square theorem: a positive integer can be expressed as a sum of 4 squares if and only if it is not of the form $4^a(8b+7)$ for integers $a,b$

Lagrange's Four Square Theorem / Bachet's conjecture: all positive integers can be expressed as a sum of 4 squares ($\forall n\in\mathbb{Z}^+,\exists a,b,c,d\in\mathbb{N}\text{ s.t. }n=a^2+b^2+c^2+d^2$)

一个用来算较小数的小代码

#include<bits/stdc++.h>
using namespace std;
int a,b,s[11111];
int main(){
	for(int i=0;i<50;i++){
		for(int j=i;j<50;j++){
			for(int k=j;k<50;k++){
				s[i*i+j*j+k*k]=1;
			}
		}
	}
	cin>>a>>b; // enter a range of values: [a,b)
	for(int i=a;i<b;i++){
		cout<<i<<" "<<s[i]<<endl;
		// 1 means expressible as the sum of 3 squares, 0 otherwise
	}
	return 0;
} 

  

原文链接: https://www.cnblogs.com/hazel-wu/p/17071739.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Sum of Squares Theorems

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/314608

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月16日 下午1:24
下一篇 2023年2月16日 下午1:26

相关推荐