1825: 会长爱数学

Time Limit: 1 Sec  Memory Limit:
128 MB

Submit: 6  Solved: 2



SubmitStatusWeb
Board

Description

陆爸爸不仅是个爱晨刷的girl,也特别喜欢数学呢。然而她已经不满足于高数线代这些简单玩意了,

她要自己定义一种运算改变世界!有一天她垂死梦中惊坐起,突然就想到了一种新的运算F(X)。

如F(123)=1*2+2*3+3*1=11。陆爸爸发现对于所有的数字来说不停的F()会进入一个循环,

f(123)=11 f(11)=2  f(2)=4   f(4)=16 f(16)=12 f(12)=4,循环节的大小就是G(x)。

现在陆爸爸要用自己的方法考验你,给你初始的x,请你计算G(x)。

Input

多实例。每组实例输入一个数字X

Output

输出G(X)

Sample Input

123

Sample Output

3












#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[10010],f[1000];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int cnt=1,ans;
int flog=0;
if(n==0)
{
printf("1\n");continue;
}
else
{
while(1)
{
memset(num,0,sizeof(num));
f[cnt]=n;
int t=0;
while(n)
{
num[t++]=n%10;
n/=10;
}
if(t>1)
{
for(int i=1;i<t;i++)
n+=num[i]*num[i-1];
n+=num[0]*num[t-1];
}
else n=f[cnt]*f[cnt];
for(int i=1;i<=cnt;i++)
{
if(f[i]==n)
{
ans=cnt-i+1;flog=1;
break;
}
}
if(flog) break;
cnt++;
}
}
printf("%d\n",ans);
}
return 0;
}

最新文章

  1. mac pro常用操作
  2. S2SH+mysql-软件开发实际部署问题-8个小时后提示MYSQL数据库无法连接
  3. java 静态方法和实例方法的区别(转)
  4. web项目引用Java项目,连接报错error HTTP Status 500 - Servlet execution threw an exception
  5. Xcode配置.pch文件
  6. HDU 5057 Argestes and Sequence --树状数组(卡内存)
  7. android语言适配
  8. Windows Phone 中查找可视化树中的某个类型的元素
  9. 【Unity3D】【NGUI】本地生成API文档
  10. OpenXml操作Word的一些操作总结. - 天天不在
  11. HW5.1
  12. Maven安装与更新
  13. VS2010与VAssistX
  14. access的保留关键字
  15. 对于crontab定时任务不能自动执行的总结
  16. voa 2015.4.29
  17. oracle和mysql分页
  18. a标签点击页面刷新但还保存当前点击的class是激活的状态
  19. SpringMVC返回json数据的三种方式(转)
  20. 前后端token机制 识别用户登录信息

热门文章

  1. shell脚本学习之ubuntu删除多余内核
  2. HDU5411CRB and Puzzle(矩阵高速幂)
  3. C/C++数据类型的转换之终极无惑
  4. 安卓获取百度地图的Api key
  5. gson的安装和使用
  6. zzulioj--1712--Monty Hall problem(蒙提霍尔问题)
  7. POJ 1949 DP?
  8. Codeforces 723D. Lakes in Berland
  9. 路飞学城-Python开发-第三章
  10. 做一个可复用的 echarts-vue 组件(延迟动画加载)