编程介的小学生 2019-06-11 09:54 采纳率: 20.5%
浏览 312

再一个乘法等式中出现所有的数字,怎么用C语言的程序编写代码设计的技术的方式来实现的呢

Problem Description
There appeared in “Nouvelles Annales de Mathematiques” the following puzzle as a modification of any of my “Canterbury Puzzles.” Arrange the nine digits in three groups of two, three, and four digits, so that the first two numbers when multiplied together make the third. Thus, 12 * 483 = 5,796. I now also propose to include the cases where there are one, four and four digits, such as 4 * 1,738 = 6,952. Can you find all possible solutions in both cases?”- Amusement in Mathematics, by Ernest Dudeney.

Now we want to arrange some of the nine digits (without ‘0’) in three groups of a, b and c digits, so that the first two numbers when multiplied together make the third. In addition, no digit can be used more than once in a single multiplication. You have to find how many solution exist there for given a, b and c.

Input
There are multiple test cases. In addition, each test case is consisting of three integers a, b, c separated by spaces.(a , b , c >= 0 && a + b + c <= 9) Meaning of a, b, and c are described in the problem statement. The last case contains exactly three 0’s for all of a, b, c and indicates the end of input stream. This line should not be processed.

Output
Your program should print a single integer for each input in a single line. The integer will state that how many solution there are for the given size of a, b and c.

Sample Input
2 3 4
1 1 1
0 0 0

Sample Output
7
4

  • 写回答

1条回答 默认 最新

  • shanizi214 2019-06-11 10:13
    关注

    import java.util.Scanner;
    public class A{
    //下面的方法是对单个数求阶乘,并返回
    public static int jieCheng(int n){
    int sum=1;
    for(int i=1;i<=n;i++){
    sum*=i;
    }
    return sum;
    }
    //下面是对所有数求阶乘,再全部相加,并返回
    public static int add(int n){
    int sum=0;
    for(int i=1;i<=n;i++){
    sum+=jieCheng(i); //调用上面的方法,对单个求阶乘,再全部相加
    }
    return sum;
    }
    public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.println("请输入数字:");
    int n=input.nextInt();
    System.out.println("运算得到:"+add(n));
    }
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示