当前位置:网站首页>OJ daily practice - Finish
OJ daily practice - Finish
2022-04-23 02:01:00 【KJ. JK】
Problem description :
If a number is exactly equal to the sum of its factors , This number is called " Complete ". for example ,6 The factor is 1、2、3, and 6=1+2+3, therefore 6 yes " Complete ". Program to find out N All the completions in , And output its factor in the following format :
Input
N
Output
? its factors are ? ? ?
Examples
Input
1000
Output
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
Java Code :
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner rd=new Scanner(System.in);
int a=rd.nextInt();
for(int i=2;i<=a;i++) {
int sum=0;
for(int j=1;j<=i/2;j++) {
if(i%j==0) {
sum=sum+j;
}
}
if(sum==i) {
System.out.print(i+" "+"its factors are"+" ");
for(int j=1;j<=i/2;j++) {
if(i%j==0) {
System.out.print(j+" ");
}
}
System.out.println();
}
}
}
}
C Code :
#include <stdio.h>
int main(){
int a;
scanf("%d",&a);
int sum;
for(int i=2;i<=a;i++){
sum=1;
for(int j=2;j<=i/2;j++){
if(i%j==0){
sum+=j;
}
}
if(sum==i){
printf("%d its factors are 1 ",i);
for(int j=2;j<=i/2;j++){
if(i%j==0){
printf("%d ",j);
}
}
printf("\n");
}
}
}
author :KJ.JK
This article is only for communication learning , Without the permission of the author , Prohibited reproduced , Let alone for other purposes , Offenders will investigate .
If the article is helpful to you , Welcome to praise or star, Your support is the greatest encouragement to the author , The shortcomings can be corrected in the comments section , Communication and learning
版权声明
本文为[KJ. JK]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220846129323.html
边栏推荐
- Use of j-link RTT
- 用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
- Echo "new password" |passwd -- stdin user name
- BGP服务器在什么业务场景会被用到?
- RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
- Shardingsphere read write separation
- 今天终于会写System.out.println()了
- How to choose a good dial-up server?
- 在使用代理IP前需要了解哪些分类?
- W801 / w800 WiFi socket development (I) - UDP
猜你喜欢
Dimension C China helping farmers in rural areas warms people's hearts the third stop is jiabaoguo farm
Challenges often faced by client project management
Is it better to use a physical machine or a virtual machine to build a website?
Analyze the advantages and disadvantages of tunnel proxy IP.
拨号vps会遇到什么问题?
搭建网站是用物理机还是云主机好?
力扣(LeetCode)112. 路径总和(2022.04.22)
Why is one plus one equal to two
如何“优雅”的测量系统性能
What are the test steps of dynamic proxy IP?
随机推荐
2022.4.10-----leetcode.804
【dpdk】10. Dpdk DNS learning notes
Redis memory recycling strategy
如何设置电脑ip?
客户端项目管理经常面临的挑战
C语言中如何“指名道姓”的进行初始化
2018 China Collegiate Programming Contest - Guilin Site J. stone game
如何“优雅”的测量系统性能
简洁开源的一款导航网站源码
2022 low voltage electrician examination questions and answers
What is an API interface?
How to write the resume of Software Test Engineer so that HR can see it?
Shardingsphere introduction and sub table usage
Digital collection platform settled in digital collection platform to develop SaaS platform of digital collection
What is a makefile file?
批处理多个文件合成一个HEX
Esp32 message queue using FreeRTOS
Cc2541 emulator CC debugger tutorial
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?