Posts

Showing posts from April, 2021

LightOJ-1336 Sigma Function

 /* Look at this problem, here, N <= 10^12, which means this is impossible to take all values on an array. Therefore, it should be a line solution or simple mathematical solution. However, you have to analyze it with pen and paper first. I am giving a concept here: Look, if we have N, then, we may cover all prime or composite numbers on the range of sqrt(N). Besides, we have to find the result of even summation. So, if we have N, then, it must have N/2 even and odd numbers. We also cover those numbers under the range of sqrt(N/2). */ #include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf typedef long long LL; const int high = 1e6+5; void divisor_sum(int N) {     int i,j, x;     for(x=1; x<=N; x++)     {         LL sum = 0;         for(i=1; i*i<=x; i++)         {             if(x%i==0)             {                 int div = x / i;                 if(div==i) sum+=i;                 else sum = sum+div+i;             }         }         if(sum%2==1

LightOJ - Shadow Sum

 Problem Link  Shadow Sum /*     Accepted     It is a data structure problem. I have used the array and map to track same positive     , negative, single, and multiple times appeared numbers. Done the summation finally. */ #include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf typedef long long LL; const LL high = 2e4 + 10; int ar[high]; map<int,int>br; map<int,int>flag; void clean() {     br.clear();     flag.clear(); } int main() {     int i, N, test, tc=0;     sf("%d", &test);     while(test--)     {         clean();         sf("%d", &N);         for(i=0;i<N;i++)         {             sf("%d", &ar[i]);         }         //for(i=0;i<N;i++) cout << br[ar[i]] << "; ";         int x , y;         for(i=0;i<N;i++)         {             x = ar[i];             if(x < 0)             {                 y = x * (-1);                 br[y] = x;             }             else