HDU 2040:親和數

來源:互聯網
上載者:User

標籤:des   style   blog   http   java   color   

親和數 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20775    Accepted Submission(s): 12590


Problem Description
古希臘數學家畢達哥拉斯在自然數研究中發現,220的所有真約數(即不是自身的約數)之和為: 

1+2+4+5+10+11+20+22+44+55+110=284。 

而284的所有真約數為1、2、4、71、 142,加起來恰好為220。人們對這樣的數感到很驚奇,並稱之為親和數。一般地講,如果兩個數中任何一個數都是另一個數的真約數之和,則這兩個數就是親和數。 

你的任務就編寫一個程式,判斷給定的兩個數是否是親和數 
Input輸入資料第一行包含一個數M,接下有M行,每行一個執行個體,包含兩個整數A,B; 其中 0 <= A,B <= 600000 ; 
Output對於每個測試執行個體,如果A和B是親和數的話輸出YES,否則輸出NO。 
Sample Input
2220 284100 200
 
Sample Output
YESNO

一道水題。。


#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int ok;void tt(int x, int y){    int sum=0;    for(int i=1; i<=x/2; i++)    {        if(x%i==0)            sum+=i;    }    if(sum==y)        ok++;}int main(){    int n;    int a, b;    scanf("%d", &n);    while( n-- )    {        ok=0;        scanf("%d%d", &a, &b);        tt(a, b);        tt(b, a);        if(ok==2)            printf("YES\n");        else            printf("NO\n");    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.