标签:style blog class c code java
数学不仅是简单而且是美的。数学很有趣,但是数学中也有很多难题,比如哥德巴赫猜想、各种欧拉定理、拉格朗日中值定理、费马定理等。今天小若遇到了一道题目:给一个9进制数,求出这个数模8的余数。小若苦思冥想很久也没有想出结果,聪明的你快来帮助小若若吧!
输入每行有一串数字(保证数字长度不超过107),有多组测试数据。以0结束输入。
对应于每组输入,首先输出数据编号(如样例所示),输出答案即可。
188 3687 0
Case 1: 1 Case 2: 0
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
string str;
int c=1;
while(cin>>str&&str!="0")
{
int len=str.length();
int num=0;
for(int i=0;i<len;i++)
{
num=(num*9+(str[i]-‘0‘))%8;
}
cout<<"Case "<<c++<<": "<<num<<endl;
}
return 0;
}
2013年北京师范大学新生程序设计竞赛网络赛--D. Number theory(模拟取余),布布扣,bubuko.com
2013年北京师范大学新生程序设计竞赛网络赛--D. Number theory(模拟取余)
标签:style blog class c code java
原文地址:http://blog.csdn.net/sr_19930829/article/details/26283275