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