Description
Input
Output
Sample Input
6 1 2 3 4 5 10
Sample Output
1 1 2 1 2 4
一点一点的找
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> using namespace std; int a[46] = {1,1,2,1,2,3,1,2,3,4,1,2,3,4,5,1,2,3,4,5,6,1,2,3,4,5,6,7,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9}; int main(){ int k; scanf("%d", &k); while(k--){ long long n; scanf("%d", &n); int flag = 0; if(n <= 45) cout << a[n - 1] << endl; else { n = n - 45; for(int i = 1; ; ++i){ for(int j = 1; j <= 9; ++j){ if(n <= (9 * i) + j){ if(n % 9 == 0) cout << "9" << endl; else cout << n % 9 << endl; flag = 1; break; } else { n -= (9 * i + j); } //cout << "N : " << n << endl; } if(flag == 1) break; } } } return 0; }