骗分过样例,
1 #define mm(a) memset(a,0,sizeof(a)); 2 #define max(x,y) (x)>(y)?(x):(y) 3 #define min(x,y) (x)<(y)?(x):(y) 4 #define Fopen freopen("1.in","r",stdin); freopen("m.out","w",stdout); 5 #define rep(i,a,b) for(ll i=(a);i<=(b);i++) 6 #define per(i,b,a) for(ll i=(b);i>=(a);i--) 7 #include<bits/stdc++.h> 8 typedef long long ll; 9 #define PII pair<ll,ll> 10 using namespace std; 11 const int INF=0x3f3f3f3f; 12 const int MAXN=(int)2e6+5; 13 14 int n; 15 bool ck(int n) 16 { 17 int x=n; 18 int cnt=0; 19 while(x!=1){ 20 if(cnt>10000)return 0; 21 cnt++; 22 int now=0; 23 while(x){ 24 now+=(x%10)*(x%10); 25 x/=10; 26 } 27 x=now; 28 } 29 return 1; 30 } 31 int main() 32 { 33 scanf("%d",&n); 34 if(ck(n))printf("true "); 35 else printf("false "); 36 return 0; 37 }
暴力出奇迹(可以开个vis数组记录然后记忆化搜索,不过懒得写了)