本文主要是介绍7-1 大美数 (15 分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
分析
- 视频讲解:
- 我不是匠人
- 求先出所有因子,然后从因子中选4个数,使得这四个数之后可以整除x
- 我的小学数学可真烂,整除的意思都没掌握。a整除b的意思是b能被a整除。
代码
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
#include <unordered_map>
#include <map>
using namespace std;int main(){int n, x;cin>>n;while(n--){cin>>x;int sq = sqrt(x);vector<int> vt; //存所有因子 for(int i = 1; i <= sq; i++){if(x%i==0){vt.push_back(i);vt.push_back(x/i);} }if(sq*sq == x) vt.pop_back();int tag = 0;int m = vt.size();for(int a = 0; a < m-3 && !tag; a++){for(int b = a+1; b < m-2 && !tag; b++){for(int c = b+1; c < m-1 && !tag; c++){for(int d = c+1; d < m; d++){int sum = vt[a]+vt[b]+vt[c]+vt[d];if(sum%x==0){tag = 1;break;}}}}}if(tag) cout<<"Yes"<<endl; else cout<<"No"<<endl; }return 0;
}
这篇关于7-1 大美数 (15 分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!