Azhar-Sheet1-G
Saraseruu
plain_text
5 months ago
910 B
1
Indexable
#include <bits/stdc++.h> #define endl "\n" #define ll long long #define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; int main() { IO; ll n; cin>>n; ll summation = n *(1+n)*(1/2) ; ll summation1 = n *(1+n)*(0.5) ; ll summation2 = n *(1+n) /2; cout<<summation1; /*Integer vs. Floating-Point Context: In the first expression (n * (1 + n) * (0.5)), the multiplication by 0.5 promotes the calculation to floating-point arithmetic. If n and (1 + n) are large enough, the product might exceed the precision limits of floating-point representation. In the second expression (n * (1 + n) / 2), the entire calculation remains in integer arithmetic until the final division by 2, which is straightforward integer division. This means it maintains precision up to the limits of long long.*/ return 0; }
Editor is loading...
Leave a Comment