有一名员工发现日历已经7天没有翻了,于是他连着翻了7页,7天的总和刚好是138,问这一天是几号?

public static int day(int sum, int n, int d)
        {
            int test = n * (n - 1) / 2;
            int test2 = (sum - test) % n;
            if (test2 == 0)
            {
                return (sum - test) / n;
            }
            else
            {
                return day(sum - d - 1, n - 1, d + 1);
            }
        }

 

posted @ 2013-06-20 15:57  ThirteenYi  阅读(506)  评论(0编辑  收藏  举报