2
Finish (5 points)
Topic content:
The factor of a positive integer is all positive integers that can be divisible by it. And if a number is exactly equal to the sum of factors other than itself, this number is called the end number. For example 6=1+2+3 (6 of the factor is the one-to-be).
Now you are going to write a program that reads two positive integers n and M (1<=n<m<1000) and outputs all the n,m in the range.
Tip: You can write a function to determine whether a number is complete.
Input format:
Two positive integers, separated by a space.
Output format:
In the meantime, all the numbers are separated by a space, and the last number has no space behind it. If not, output one line of text:
NIL
(output nil three uppercase letters plus a carriage return).
Input Sample:
1 10
Sample output:
6
Time limit: 500ms memory limit: 32000kb
main.c// C yuyan//// Created by Anzhongyin on 2016/11/29.// Copyright 2016 anzhongyin. All rights reserved.//#include <stdio.h> #include <math.h>int perfnumber (int i); int main (int argc, const char * argv[]) { //Insert code here ... TODO auto-generated method stub int n,m; scanf ("%d%d", &n,&m); int b=0; for (int i=n+1;i<m;i++) { if (Perfnumber (i)) { if (!b) { printf ("%d", I); b=1; } else { printf ("%d", i); }}} if (!b) { printf ("NIL"); } printf ("\ n");} int perfnumber (int i) { int per=1; for (int j=2;j<i;j++) { if (i%j==0) { per+=j; } } if (per!=i) { i=0; } return i;}
Use case test Results |
Run time |
Memory consumption |
Tips |
Score |
Use Case 1 by |
1ms |
136kb |
|
1 |
Use Case 2 by |
3ms |
256kb |
|
2 |
Use Case 3 by |
1ms |
256kb |
|
2 |
Submit an Answer
Score/Score:5.00/5.00 min
Introduction to Programming--c Language 6th week programming Exercise 2 finish (5 points)