码迷,mamicode.com
首页 > 其他好文 > 详细

计算机17-3,4作业F

时间:2018-05-08 14:48:49      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ali   tin   util   style   mat   tput   stat   tle   asn   

F.complete number problem with formatted output

 
Description
同题目E
Input
N
Output

complete numbers within 2~N

Sample Input

10

100

Sample Output

6=1+2+3

6=1+2+3

28=1+2+4+7+14

 

 1 import java.util.*;
 2 public class Main{
 3     public static void main(String[] args){
 4         Scanner in = new Scanner(System.in);
 5         while(in.hasNext()){
 6             int num = in.nextInt();
 7             for(int i=6;i<=num;i++){
 8                 int sum = 0;
 9                 int[] arr = new int[100];
10                 int k = 0;
11                 for(int j=1;j<i;j++)
12                     if(i%j==0){
13                         sum += j;
14                         arr[k++] = j;
15                     }
16                 if(sum==i){
17                     System.out.print(i+"=");
18                     for(int l=0;l<k;l++){
19                         System.out.print(arr[l]);
20                         if(l!=k-1)
21                             System.out.print("+");
22                     }
23                     System.out.println();
24                 }
25             }
26         }
27     }
28 }

 

计算机17-3,4作业F

标签:ali   tin   util   style   mat   tput   stat   tle   asn   

原文地址:https://www.cnblogs.com/1Kasshole/p/9007371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!