/**题目:一筐鸡蛋 1个1个拿,正好拿完。 2个2个拿,还剩1个。 3个3个拿,正好拿完。 4个4个拿,还剩1个。 5个5个拿,还差1个。 6个6个拿,还剩3个。 7个7个拿,正好拿完。 8个8个拿,还剩1个。 9个9个拿,正好拿完。 问:鸡蛋有多少个? **/ --edit @2017-2-21 DECLARE @n INT , @bflag BIT , @icount INT --计数 DECLARE @t TABLE ( 蛋的个数 INT , 每次2个剩余 INT , 每次3个剩余 INT , 每次4个剩余 INT , 每次5个剩余 INT , 每次6个剩余 INT , 每次7个剩余 INT , 每次8个剩余 INT , 每次9个剩余 INT ) SELECT @n = 0 , @bflag = 0 , @icount = 0 WHILE @n >= 0 AND @bflag = 0 BEGIN IF @n % 2 = 1 AND @n % 3 = 0 AND @n % 4 = 1 AND ( @n + 1 ) % 5 = 0 AND @n % 6 = 3 AND @n % 7 = 0 AND @n % 8 = 1 AND @n % 9 = 0 BEGIN INSERT INTO @t SELECT @n AS 蛋的个数 , @n % 2 AS 每次2个剩余 , @n % 3 AS 每次3个剩余 , @n % 4 AS 每次4个剩余 , @n % 5 AS 每次5个剩余 , @n % 6 AS 每次6个剩余 , @n % 7 AS 每次7个剩余 , @n % 8 AS 每次8个剩余 , @n % 9 AS 每次9个剩余 SET @icount = @icount + 1 IF @icount = 10 --找到10个后退出循环 BEGIN SET @bflag = 1 END END SET @n = @n + 63 END SELECT * FROM @t