Advertisement
Dsxv

series_digit_square_sum_<=x

Jul 27th, 2020 (edited)
1,380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. #define int long long
  5. const int mod = 998244353 ;
  6. const int N = 1e5 + 10 ;
  7. vector<int> ser ;
  8.  
  9. void solve(int x){
  10.     queue<pair<int,int>> q ;
  11.     q.push({0,0}) ;
  12.     while(ser.size() <= N){
  13.         auto [cur,sum] = q.front() ;
  14.         if(sum) ser.push_back(cur) ;
  15.         q.pop() ;
  16.         for(int i = 0 ; i < 10 ; i++){
  17.         if(sum == 0 && i == 0) continue ;
  18.             if(sum + i*i <= x){
  19.                 q.push({(cur*10 + i)%mod , sum + i*i}) ;
  20.             }
  21.         }
  22.     }
  23. }
  24.    
  25.  
  26. int32_t main(){
  27.     int x ;
  28.     cin >> x ;
  29.     solve(x) ;
  30.     // series stored in `ser`
  31.     for(int i = 0 ; i < 10 ; i++) cout << ser[i] << '\n' ;
  32.     return 0 ;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement