Solutions of Loop - MarisaOJ: Marisa Online Judge

Solutions of Loop

Select solution language

Write solution here.


User Avatar toshirohitsugaya    Created at    4 likes

``` #include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll l,r; cin >> l >> r; for(int i = l ;i <= r;i++){ cout << i << " "; } return 0; } ```

omegumunot    Created at    1 likes

# Loop ## Idea We can use a for loop to iterate over all numbers from $l$ to $r$ and print it in $O(r - l)$. ## Code ``` #include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1E9 + 7; const int INF = 1E9; const ll INFLL = 1E18; int l; int r; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> l >> r; for(int i = l; i <= r; i++) { cout << i << "\n"; } } ```