programming-challenges Ones (110504) 题解

来源:互联网 发布:防水纹身贴淘宝 编辑:程序博客网 时间:2024/05/19 17:49

这道题也看了参考答案,主要的思路是利用了模运算可以分解的性质,从而避免了运算溢出的问题。思路可以参看:http://www.tuicool.com/articles/rEZriy


代码:

#include <iostream>#include <sstream>#include <fstream>#include <string>#include <vector>#include <queue>#include <map>#include <set>#include <stack>#include <assert.h>#include <algorithm>#include <math.h>#include <ctime>#include <functional>#include <string.h>#include <stdio.h>#include <numeric>#include <float.h>using namespace std;int main() {int i = 0; while (cin >> i) {int temp = 1; int ans = 1; do {if (temp % i == 0) break;ans++; temp = (temp * (10 % i) + 1) % i; } while (true);cout << ans << endl; }return 0; }


0 0