結果
問題 | No.1168 Digit Sum Sequence |
ユーザー |
![]() |
提出日時 | 2020-08-14 21:23:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,589 bytes |
コンパイル時間 | 12,345 ms |
コンパイル使用メモリ | 560,320 KB |
最終ジャッジ日時 | 2025-01-12 23:08:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
//header{{{ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <boost/sort/spreadsort/spreadsort.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> //#include <boost/graph/adjacency_list.hpp> //#include <boost/graph/dijkstra_shortest_paths.hpp> //#include <boost/graph/graph_utility.hpp> using namespace std; //using namespace boost::multiprecision; //using namespace boost::math; /* typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, int> > Graph; */ #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() #define Fixed fixed << setprecision(12) #define bsort boost::sort::spreadsort::spreadsort #define int int_fast64_t using pii = pair<int,int>; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9+7; constexpr int mod2 = 998244353; template <class Func> class FixPoint : Func { public: explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template <class... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(*this, std::forward<Args>(args)...); } }; template <class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func>{forward<Func>(f)}; } template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >; template <class T> using max_heap = priority_queue<T>; template <class A, class B> using umap = unordered_map<A,B>; inline int square(int a){ return a * a;} inline int updiv(int a,int b){ return (a + b - 1) / b; } constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; struct negrightshift { inline int operator() (const int &x, const unsigned offset) { return -(x >> offset); } }; //}}} int dsum(int n){ int sum = 0; while(n){ sum += n % 10; n /= 10; } return (sum); } signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout.setf(ios_base::fixed); cout.precision(10); int n; cin >> n; while(true){ int x = dsum(n); if(x == n) return cout << x << '\n', 0; n = x; } return 0; }