poj1047 数论
2016-04-20 22:02
295 查看
题意:输入一个数(该整数的长度为2~60),判断该数是否是循环数。设该整数的长度为n,所谓循环数,是指该数分别乘以1~n,得到的数发生循环。
算法:循环数规律,若某数a是循环数, 则a*(n+1)所得的结果全是9
#include <iostream>
#include <string.h>
using namespace std;
char str[100];
int main()
{
while (cin >> str)
{
bool flag = true;
int n = strlen(str) + 1;
int b = 0; // 进位
for (int i=n-2; i>=0; i--)
{
int a = (str[i]-'0')*n + b;
b = a / 10;
int c = a % 10;
if (c != 9)
{
flag = false;
break;
}
}
(flag)? cout << str << " is cyclic" << endl : cout << str << " is not cyclic" << endl;
}
}
算法:循环数规律,若某数a是循环数, 则a*(n+1)所得的结果全是9
#include <iostream>
#include <string.h>
using namespace std;
char str[100];
int main()
{
while (cin >> str)
{
bool flag = true;
int n = strlen(str) + 1;
int b = 0; // 进位
for (int i=n-2; i>=0; i--)
{
int a = (str[i]-'0')*n + b;
b = a / 10;
int c = a % 10;
if (c != 9)
{
flag = false;
break;
}
}
(flag)? cout << str << " is cyclic" << endl : cout << str << " is not cyclic" << endl;
}
}
相关文章推荐
- 1.m分解阶乘之和
- 2.几种递推数
- 3.欧拉函数
- 4.快速幂模m算法
- 5.扩展欧几里得&&中国剩余定理
- 6.数论_web
- 初学ACM - 组合数学基础题目PKU 1833
- Project Euler Problem 387 - Harshad Numbers - 深度优先
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列