C# 数字相除

Problem description

  定理:把一个至少两位的正整数的个位数字去掉,再从余下的数中减去个位数的5倍。当且仅当差是17的倍数时,原数也是17的倍数 。

例如,34是17的倍数,因为3-20=-17是17的倍数;201不是17的倍数,因为20-5=15不是17的倍数。输入一个正整数n,你的任务是判断它是否是17的倍数。

Input

  输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=10100),表示待判断的正整数。n=0表示输入结束,你的程序不应当处理这一行。

Output

  对于每组测试数据,输出一行,表示相应的n是否是17的倍数。1表示是,0表示否。

Sample Input

34

201

2098765413

1717171717171717171717171717171717171717171717171718

0

Sample Output

1

0

1

0

Problem Source

  The Sixth Hunan Collegiate Programming Contest 

 题目连接:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10932

//整数相除 //.Net4.0支持大数System.Numerics.dll
        [WebMethod]
        public int IntDiv(BigInteger n)
        {
            BigInteger z = n / 10;
            int y = (int)(n-z * 10);
            int y5=y*5;
            if ((z -y5)%17 == 0) return 1;
            return 0;
        }
        [WebMethod]
        public void IntDiv_Test_Loop()
        {

            BigInteger n = 2098765413;   //.Net4.0支持大数
            //for (BigInteger i = 10; i < n; i++)
            //{
            //    this.Context.Response.Write(i.ToString() + "=" + IntDiv(i).ToString() + "<br>");
            //}
            //
            n=34;
            this.Context.Response.Write(n.ToString() + "=" + IntDiv(n).ToString() + "<br>");
            n=201;
            this.Context.Response.Write(n.ToString() + "=" + IntDiv(n).ToString() + "<br>");
            n=2098765413;
            this.Context.Response.Write(n.ToString() + "=" + IntDiv(n).ToString() + "<br>");
            string dn = "1717171717171717171717171717171717171717171717171718";
            n = BigInteger.Parse(dn);
            this.Context.Response.Write(n.ToString() + "=" + IntDiv(n).ToString() + "<br>");
            
        }
结果为:

原数字=判断结果(1表示是,0表示否)

34=1
201=0
2098765413=1
1717171717171717171717171717171717171717171717171718=0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值