日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

P1586 四方定理

發布時間:2025/3/21 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P1586 四方定理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

四方定理是眾所周知的:任意一個正整數nn?,可以分解為不超過四個整數的平方和。例如:25=1^{2}+2^{2}+2^{2}+4^{2}25=12+22+22+42?,當然還有其他的分解方案,25=4^{2}+3^{2}25=42+32?和25=5^{2}25=52?。給定的正整數nn?,編程統計它能分解的方案總數。注意:25=4^{2}+3^{2}25=42+32?和25=3^{2}+4^{2}25=32+42?視為一種方案。

輸入輸出格式

輸入格式:

?

第一行為正整數tt?(t\le 100t100?),接下來tt?行,每行一個正整數nn?(n\le 32768n32768?)。

?

輸出格式:

?

對于每個正整數nn?,輸出方案總數。

?

輸入輸出樣例

輸入樣例#1:?復制 1 2003 輸出樣例#1:?復制 48

#include <bits/stdc++.h> using namespace std; typedef long long ll; #define inf 2147483647 const ll INF = 0x3f3f3f3f3f3f3f3fll; #define ri register int template <class T> inline T min(T a, T b, T c) {return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) {return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) {return min(min(a, b), min(c, d)); } template <class T> inline T max(T a, T b, T c, T d) {return max(max(a, b), max(c, d)); } #define scanf1(x) scanf("%d", &x) #define scanf2(x, y) scanf("%d%d", &x, &y) #define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X) #define pi acos(-1) #define me(x, y) memset(x, y, sizeof(x)); #define For(i, a, b) for (int i = a; i <= b; i++) #define FFor(i, a, b) for (int i = a; i >= b; i--) #define bug printf("***********\n"); #define mp make_pair #define pb push_back const int maxn = 10005; // name******************************* int f[33000][10]; int t; int n=32768; int ans=0; // function******************************//*************************************** int main() { // ios::sync_with_stdio(0); // cin.tie(0); // freopen("test.txt", "r", stdin);// freopen("outout.txt","w",stdout);me(f,0);f[0][0]=1;for(int i=1; i*i<=n; i++)for(int j=i*i; j<=n; j++)for(int k=1; k<=4; k++)f[j][k]+=f[j-i*i][k-1];cin>>t;while(t--){ans=0;cin>>n;For(i,1,4)ans+=f[n][i];cout<<ans<<endl;}return 0; }

轉載于:https://www.cnblogs.com/planche/p/8650454.html

總結

以上是生活随笔為你收集整理的P1586 四方定理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。