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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

JustOj 1032: 习题6.7 完数

發(fā)布時間:2023/12/2 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JustOj 1032: 习题6.7 完数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目描述

一個數(shù)如果恰好等于它的因子之和,這個數(shù)就稱為"完數(shù)"。 例如,6的因子為1、2、3,而6=1+2+3,因此6是"完數(shù)"。 編程序找出N之內(nèi)的所有完數(shù),并按下面格式輸出其因子:

輸入

N

輸出

? its factors are ? ? ?

樣例輸入
1000
樣例輸出
6 its factors are 1 2 3 28 its factors are 1 2 4 7 14 496 its factors are 1 2 4 8 16 31 62 124 248

題解:枚舉即可 學校oj暫時不能測試但是樣例是對的附下圖 (歡迎路過的大佬指出錯誤)



1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 using namespace std; 13 #define lowbit(x) (x&(-x)) 14 #define max(x,y) (x>y?x:y) 15 #define min(x,y) (x<y?x:y) 16 #define MAX 100000000000000000 17 #define MOD 1000000007 18 #define pi acos(-1.0) 19 #define ei exp(1) 20 #define PI 3.141592653589793238462 21 #define INF 0x3f3f3f3f3f 22 #define mem(a) (memset(a,0,sizeof(a))) 23 typedef long long ll; 24 ll gcd(ll a,ll b){ 25 return b?gcd(b,a%b):a; 26 } 27 const int N=2005; 28 const int mod=1e9+7; 29 void la(int n) 30 { 31 int s=n-1,flag=0; 32 for(int i=2;i*i<=n;i++){ 33 if(n%i==0) s-=i+n/i; 34 } 35 if(s==0) flag=1; 36 if(flag){ 37 cout<<n<<" its factors are"; 38 for(int i=1;i<n;i++){ 39 if(n%i==0){ 40 cout<<" "<<i; 41 } 42 } 43 cout<<endl; 44 } 45 } 46 int main() 47 { 48 std::ios::sync_with_stdio(false); 49 int n; 50 cin>>n; 51 for(int i=2;i<=n;i++){ 52 la(i); 53 } 54 return 0; 55 }

轉(zhuǎn)載于:https://www.cnblogs.com/shixinzei/p/7267104.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的JustOj 1032: 习题6.7 完数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。