fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[1000][1000], n, m, count1 = 1, count2 = 1, result = 0;
  6. cin >> n >> m;
  7. for (int i = 0; i < n; i++)
  8. for (int j = 0; j < m; j++)
  9. arr[i][j] = count1++;
  10. for (int j = 0; j < m; j++) {
  11. for (int i = 0; i < n; i++) {
  12. if(arr[i][j] == count2) result++;
  13. count2++;
  14. }
  15. }
  16. cout << result << "\n";
  17. }
Success #stdin #stdout 0s 19016KB
stdin
3 3
stdout
3