fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ld long double
  5. #define e "\n"
  6. #define int int64_t
  7. #define pb push_back
  8. #define all(v) ((v).begin()),((v).end())
  9. #define allr(v) ((v).rbegin()),((v).rend())
  10. #define V vector<int>
  11. #define cin(vec) for(auto &i:vec)cin>>i;
  12. #define cout(vec) for(auto &i:vec)cout<<i<<' ';
  13. #define fast ios_base:sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
  14. void fileIO() {
  15. #ifndef ONLINE_JUDGE
  16. freopen("", "r", stdin);
  17. freopen("output.txt", "w", stdout);
  18. #endif
  19. }
  20.  
  21. vector<vector<int>>chess_board;
  22. vector<vector<vector<int>>>ans;
  23. bool safe(int r,int c,int n) {
  24. int i,j;
  25. for(i=0;i<c;i++) {
  26. if(chess_board[r][i]==1000) return false;
  27. }
  28. for(int i=r,j=c;i>=0&&j>=0;i--,j--) {
  29. if(chess_board[i][j]==1000) return false;
  30. }
  31. for(i=r,j=c;i<n&&j>=0;i++,j--) {
  32. if(chess_board[i][j]==1000) return false;
  33. }
  34. return true;
  35. }
  36. void rec(int c,int n) {
  37. if(c==n) {
  38. ans.pb(chess_board);
  39. }
  40. for(int i=0;i<n;i++) {
  41. if(safe(i,c,n)) {
  42. int t=chess_board[i][c];
  43. chess_board[i][c]=1000;
  44. rec(c+1,n);
  45. chess_board[i][c]=t;
  46. }
  47. }
  48. }
  49. bool cmp(pair<string ,int>&a,pair<string ,int>&b) {
  50. if (a.second==b.second) {
  51. return a.first<b.first;
  52. }
  53. return a.second>b.second;
  54.  
  55.  
  56. }
  57. bool can(int mid,int k,V&v) {
  58. int c=0;
  59. for(int i=0;i<v.size();i++) {
  60. if(v[i]<mid) {
  61. c++;
  62. }else {
  63. c=0;
  64. }
  65. if(c>k)return false;
  66. }
  67. return 1;
  68. }
  69. signed main() {
  70. ios_base::sync_with_stdio(0);cin.tie(NULL);
  71. int t=1;
  72. cin>>t;
  73. int z=1;
  74. while(t--) {
  75. int n,s;
  76. cin>>n>>s;
  77. int ans=0;
  78. for(int i=s;i<=n;i*=s) {
  79. ans+=n/i;
  80. }
  81. cout<<"Case "<<z<<": "<<ans<<e;
  82. z++;
  83. }
  84.  
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
Success #stdin #stdout 0.01s 5320KB
stdin
7
0
662573
10000
18898541
32385559
4
6
stdout
Case 1: 0
Case 2: 0
Case 3: 10795179
Case 4: 1
Case 5: 1
Case 6: 1
Case 7: 1