Guest User

Untitled

a guest
Dec 19th, 2011
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #pragma comment(linker,"/STACK:300000000")
  2. #define _CRT_SECURE_NO_WARNINGS
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <map>
  10. #include <set>
  11. #include <iomanip>
  12. #include <memory.h>
  13. #include <cstdio>
  14. #include <sstream>
  15. #include <deque>
  16. #include <bitset>
  17. #include <numeric>
  18. #include <ctime>
  19. #include <queue>
  20.  
  21. using namespace std;
  22.  
  23. #define show(x) cout << #x << " = " << (x) << endl;
  24. #define fori(i,n) for(int i = 0; i < (n); i++)
  25. #define forab(i,a,b) for(int i = (a); i <= (b); i++)
  26. #define sz(v) int((v).size())
  27. #define all(v) (v).begin(),(v).end()
  28. const double pi = 3.1415926535897932384626433832795;
  29. template<class T> T abs(const T &a) { return a >= 0 ? a : -a; };
  30. template<class T> T sqr(const T &x) { return x * x; }
  31. typedef pair<int,int> ii;
  32. typedef long long ll;
  33. ///////////////////////////////////////
  34.  
  35. const int billion = 1000000000;
  36. const int P = 100000;
  37. int s;
  38. int prec[P];
  39.  
  40. int digSum(int n)
  41. {
  42.     int r = 0;
  43.     while(n)
  44.     {
  45.         r += n%10;
  46.         n /= 10;
  47.     }
  48.     return r;
  49. }
  50.  
  51. int main()
  52. {
  53. #ifndef ONLINE_JUDGE
  54.     freopen("input.txt","r",stdin);
  55.     freopen("output.txt","w",stdout);
  56. #endif
  57.     cin >> s;
  58.     fori(i,P)
  59.         prec[i] = digSum(i);
  60.     int ans = 0, a;
  61.     fori(i,billion/P)
  62.     {
  63.         a = s-prec[i];
  64.         fori(j,P)
  65.             ans += (prec[j] == a);
  66.     }
  67.     if(s == 1)
  68.         ans++;
  69.     cout << ans;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment