题解 | #大整数的因子#

大整数的因子

https://www.nowcoder.com/practice/3d6cee12fbf54ea99bb165cbaba5823d

//Java版代码
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            BigInteger c = sc.nextBigInteger();
            if (c.equals(BigInteger.valueOf(-1))) break;
            
            boolean flag = true;
            for (int k = 2; k <= 9; k++) {
                if (c.mod(BigInteger.valueOf(k)).equals(BigInteger.ZERO)) {
                    System.out.print(k + " ");
                    flag = false;
                }
            }
            if (flag) System.out.print("none");
            System.out.println();
        }
    }
}
#Python版代码
while True:
    try:
        c = int(input())
        if c == -1: break
        flag = True
        for k in range(2, 10):
            if c % k == 0:
                print(k, end=' ')
                flag = False
        if flag: print("none")
        print()
    except:
        break

全部评论

相关推荐

下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务