fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. class Main{
  4. static int c = 1;
  5. static String c(long a, long b, int o){
  6. return p((o < 1 ? a+b : a*b) + "", o) + "," + c;
  7. }
  8.  
  9. static long p(String n, int o){
  10. long x = o,
  11. q;
  12. for(String s : n.split("")){
  13. q = new Long(s);
  14. x = o < 1
  15. ? x + q
  16. : x * q;
  17. }
  18. c++;
  19. return x < 10
  20. ? x
  21. : p(x+"", o);
  22. }
  23.  
  24. public static void main(String[] a){
  25. System.out.println(c(81, 31, 0));
  26. c = 1;
  27. System.out.println(c(351, 14568, 0));
  28. c = 1;
  29. System.out.println(c(21, 111, 1));
  30. c = 1;
  31. System.out.println(c(136, 2356, 1));
  32. }
  33. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
4,2
6,3
8,3
0,2