Advertisement
Saleh127

UVA 944

Oct 12th, 2020
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll happ[100005];
  6. ll xxx(ll a)
  7. {
  8. ll ans=0,r=0;
  9. while(a)
  10. {
  11. r=a%10;
  12. ans+=(r*r);
  13. a/=10;
  14. }
  15. return ans;
  16. }
  17.  
  18. void cal()
  19. {
  20. ll i,j;
  21. for(i=1;i<=99999;i++)
  22. {
  23. ll n=i,cnt=0;
  24. while(n>9)
  25. {
  26. n=xxx(n);
  27. cnt++;
  28. }
  29. if(n==7)
  30. {
  31. cnt+=5;
  32. n=1;
  33. }
  34. if(n==1)
  35. {
  36. happ[i]=cnt+1;
  37. }
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. ios_base::sync_with_stdio(0);
  44. cin.tie(0);cout.tie(0);
  45.  
  46. cal();
  47.  
  48. ll a,c,d,e,f,i,j,k,l=0;
  49.  
  50. while(cin>>a>>c)
  51. {
  52. l++;
  53. if(l>1) cout<<endl;
  54. for(i=a;i<=c;i++)
  55. {
  56. if(happ[i]) cout<<i<<" "<<happ[i]<<endl;
  57. }
  58. }
  59. return 0;
  60. }
  61.  
Advertisement
RAW Paste Data Copied
Advertisement