Sdut OJ 1221 Affinity Number (Find a number n all factors, only need violence: 2->SQRT (n))

Source: Internet
Author: User

Affinity number Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ The topic describes if the factor of a and equals b,b factor and equals A, and a≠b, is called A, B is the affinity number pair. For example, the sum of all true approximations of 220 (i.e. not their own approximations) is: 1+2+4+5+10+11+20+22+44+55+110=284. 284 of all true approximate and for: 1+2+4+71+142=220. Your task is to write a program that determines whether a given two number is an affinity number. Input input data The first line contains a number m, followed by a M row, an instance per line, containing two integers, a, a, and a 0≤a,b≤99999. Output yes for each test instance if a and B are affinity numbers, otherwise output no. Sample input
2220 284100 200
Sample output
YESNO
Code:

#include <stdio.h> #include <string.h> #include <math.h>int main () {int n, m;int dd, ff;int i, J;int T;sca NF ("%d", &t), while (t--) {scanf ("%d%d", &n, &m);        dd=1;ff=1;        for (i=2; i<=sqrt (n); i++) {if (n%i==0) {dd=dd+i+ (n/i);}} for (j=2; j<=sqrt (m); j + +) {if (m%j==0) {ff=ff+j+ (m/j);}} if (dd==m && ff==n) {printf ("yes\n");} else{printf ("no\n");}} return 0;} /**************************************problem Id:sdut OJ 1221 result:accepted take memory:276k take time:0ms Submit T ime:2015-01-09 19:49:49  **************************************/

Sdut OJ 1221 Affinity Number (Find a number n all factors, only need violence: 2->SQRT (n))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.