579

# 题目

## Description

1ˆ2+2ˆ2+3ˆ2+4ˆ2=1+4+9+16=30
3ˆ2+0ˆ2=9
9ˆ2=81
8ˆ2+1ˆ2=64+1=65
6ˆ2+5ˆ2=36+25=61
6ˆ2+1ˆ2=36+1=37
3ˆ2+7ˆ2=9+49=58
5ˆ2+8ˆ2=25+64=89
8ˆ2+9ˆ2=64+81=145
1ˆ2+4ˆ2+5ˆ2=1+16+25=42
4ˆ2+2ˆ2=16+4=20
2ˆ2+0ˆ2=4+0=4
4ˆ2=16
1ˆ2+6ˆ2=1+36=37

1234
67834807
0

## Sample Output

1234 30 9 81 65 61 37 58 89 145 42 20 4 16 37
67834807 287 117 51 26 40 16 37 58 89 145 42 20 4 16

# 代码

/*
By:OhYee
Github:OhYee
HomePage:http://www.oyohyee.com
Email:oyohyee@oyohyee.com
Blog:http://www.cnblogs.com/ohyee/

かしこいかわいい？
エリーチカ！

*/

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
using namespace std;

//DEBUG MODE
#define debug 0

//循环
#define REP(n) for(int o=0;o<n;o++)

const int maxn = 1005;
bool visited[maxn];

inline int sq(int n) {
int ans = 0;
while(n) {
ans += (n % 10)*(n % 10);
n /= 10;
}
return ans;
}

bool Do() {
int n;
if(scanf("%d",&n),n == 0)
return false;

memset(visited,false,sizeof(visited));
int k = n;
while(k>maxn||!visited[k]) {
if(k < maxn)
visited[k] = true;
printf("%d   ",k);
k = sq(k);
}
printf("%d   \n",k);
return true;
}

int main() {
while(Do());
return 0;
}

• 点击查看/关闭被识别为广告的评论