Time to be myself

hy I am telling this to myself after thinking about a girls happiness for 2 years.

when it started it was not that intense it was fun but when you helping someone and they continue to need your help and you don’t want to hurt them and nothing make sense without seeing her happy then your just like me. But the funny part is the person I am helping to get her work done and see her happy is still a stranger to me.

Yeah she is still a stranger. I don’t even know if she consider me friend. I am helping her solve complex problems which are a fun puzzles to me but I just want her to realise that how much time I gave her is to be friend of her.

its like not really funny it’s like a psycho shit taught to write this with lot of fun but shit.

no one reads it anyway and she will never find this out. So I am writing this. But will not write anything. Not a good time for that feelings. Will write it one I get my financial freedom to waste money and not my time.

😊 until then some feelings are better buried under a million stones.

Don’t make sense right being myself yeah but this is stupid.

I tried a lot to optmize

Question available in my posts

I couldn’t optimize it used 2 buffers but still same timing out

using System;
using System.Collections.Generic;
using System.IO;using System.Linq;
class Solution {
    static void Main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        int total=int.Parse(Console.ReadLine());
        for(int i=0;i<total;i++){
            string str=Console.ReadLine();
            int number=int.Parse(str.Split(‘ ‘)[0]);
            int m=int.Parse(str.Split(‘ ‘)[1]);
            Console.WriteLine(calculate(number)%m);
        }
    }
    static Dictionary<int,long> buffer=new Dictionary<int,long>();
    static Dictionary<int,int> buffer2=new Dictionary<int,int>();
    static long calculate(int number){
        return sigmat(number);
    }
    static int g(int n){
        int i=0;
        bool sum=false;
        i=buffercheck2(n,ref sum); 
        if(sum){
            return i;
        }
        int sfOutput=sf(i);
        buffer2.Add(i,sfOutput);
        while(sfOutput!=n){
            i++;
            sfOutput=sf(i);
            buffer2.Add(i,sfOutput);
        }
        return i;
    }
    static long sigmat(int n){
        long sum=0;
        int buff=buffercheck(n,ref sum)+1; 
        for(int i=buff;i<=n;i++){
            int sgval=sg(i);
            sum+=sgval;
            buffer.Add(i,sum);
        }
        return sum;
    }
    static int buffercheck(int n,ref long sum){
        int max=0;
        if(n<buffer.Count){
        for(int i=0;i<buffer.Count;i++){
            if(max<=buffer.ElementAt(i).Key && buffer.ElementAt(i).Key <=n ){
                
                max=buffer.ElementAt(i).Key;
                sum=buffer.ElementAt(i).Value;
                if(max==n) {
                    return n;
                }
            }  
        }
        }
        else{
            if(buffer.Count>1){
            sum=buffer[buffer.Count];
            max=buffer.Count;
            }
        }
        return max;
    }
      static int buffercheck2(int n,ref bool sum){
        int max=buffer2.Count;
        for(int i=0;i<max;i++){
            if(buffer2.ContainsValue(n)){  
                sum=true;
                for(int j=0;j<buffer2.Count;j++)
                {
                    if(buffer2[j]==n){
                        return j;
                    }
                }  
                return 0;
            }  
        }
        return max-1;
    }
    static int sg(int n){
        n=g(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    static int f(int n){
        int sum=0;
        while(n>0){
            int sumA=n%10;
            int factorial=1;
            while(sumA>1){
                factorial*=(sumA–);
            }
            sum+=factorial;
            n=n/10;
        }
        return sum;
    }
    static int sf(int n){
        n=f(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    
}

Tried to optimize with 2 buffers

but didn’t worked looks like I am using wrong libraries 😂🤣🤦‍♂️

using System;
using System.Collections.Generic;
using System.IO;using System.Linq;
class Solution {
    static void Main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        int total=int.Parse(Console.ReadLine());
        for(int i=0;i<total;i++){
            string str=Console.ReadLine();
            int number=int.Parse(str.Split(‘ ‘)[0]);
            int m=int.Parse(str.Split(‘ ‘)[1]);
            Console.WriteLine(calculate(number)%m);
        }
    }
    static Dictionary<int,long> buffer=new Dictionary<int,long>();
    static Dictionary<int,int> buffer2=new Dictionary<int,int>();
    static long calculate(int number){
        return sigmat(number);
    }
    static int g(int n){
        int i=0;
        bool sum=false;
        i=buffercheck2(n,ref sum); 
        if(sum){
            return i;
        }
        int sfOutput=sf(i);
        buffer2.Add(i,sfOutput);
        while(sfOutput!=n){
            i++;
            sfOutput=sf(i);
            buffer2.Add(i,sfOutput);
        }
        return i;
    }
    static long sigmat(int n){
        long sum=0;
        int buff=buffercheck(n,ref sum)+1; 
        for(int i=buff;i<=n;i++){
            int sgval=sg(i);
            sum+=sgval;
            buffer.Add(i,sum);
        }
        return sum;
    }
    static int buffercheck(int n,ref long sum){
        int max=0;
        for(int i=0;i<buffer.Count;i++){
            if(max<=buffer.ElementAt(i).Key && buffer.ElementAt(i).Key <=n ){
                
                max=buffer.ElementAt(i).Key;
                sum=buffer.ElementAt(i).Value;
                if(max==n) {
                    return n;
                }
            }  
        }
        return max;
    }
      static int buffercheck2(int n,ref bool sum){
        int max=buffer2.Count;
        for(int i=0;i<max;i++){
            if(buffer2.ContainsValue(n)){  
                sum=true;
                for(int j=0;j<buffer2.Count;j++)
                {
                    if(buffer2[j]==n){
                        return j;
                    }
                }  
                return 0;
            }  
        }
        return max-1;
    }
    static int sg(int n){
        n=g(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    static int f(int n){
        int sum=0;
        while(n>0){
            int sumA=n%10;
            int factorial=1;
            while(sumA>1){
                factorial*=(sumA–);
            }
            sum+=factorial;
            n=n/10;
        }
        return sum;
    }
    static int sf(int n){
        n=f(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    
}

I tried optimizing code with buffer

using System;
using System.Collections.Generic;
using System.IO;using System.Linq;
class Solution {
    static void Main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        int total=int.Parse(Console.ReadLine());
        for(int i=0;i<total;i++){
            string str=Console.ReadLine();
            int number=int.Parse(str.Split(‘ ‘)[0]);
            int m=int.Parse(str.Split(‘ ‘)[1]);
            Console.WriteLine(calculate(number)%m);
        }
    }
    static Dictionary<int,long> buffer=new Dictionary<int,long>();
    static long calculate(int number){
        return sigmat(number);
    }
    static int g(int n){
        int i=0;
        while(sf(i)!=n){
            i++;
        }
        return i;
    }
    static long sigmat(int n){
        long sum=0;
        int buff=buffercheck(n,ref sum)+1;
        for(int i=buff;i<=n;i++){
            int sgval=sg(i);
            sum+=sgval;
            buffer.Add(i,sum);
        }
        return sum;
    }
    static int buffercheck(int n,ref long sum){
        int max=0;
        for(int i=0;i<buffer.Count;i++){
            if(max<=buffer.ElementAt(i).Key && buffer.ElementAt(i).Key <=n ){
                max=buffer.ElementAt(i).Key;
                sum=buffer.ElementAt(i).Value;
                if(max==n) {
                    return n;
                }
            }
        }
        return max;
    }
    static int sg(int n){
        n=g(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    static int f(int n){
        int sum=0;
        while(n>0){
            int sumA=n%10;
            int factorial=1;
            while(sumA>1){
                factorial*=(sumA–);
            }
            sum+=factorial;
            n=n/10;
        }
        return sum;
    }
    static int sf(int n){
        n=f(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
}

What am I doing

I really don’t know just trying to solve a problem

This above question now time is 7:37 I took like 20min to understand 🤣😂

I haven’t had practice coding questions like this I am a web developer not a coding freek.

my code solution for now is incomplete but let’s try this out

using System;using System.Collections.Generic;using System.IO;class Solution {    static void Main(String[] args) {        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */        int total=int.Parse(Console.ReadLine());        for(int i=0;i<total;i++){            int number=int.Parse(Console.ReadLine().Split(‘ ‘)[0]);            Console.WriteLine(calculate(number));        }    }    static int calculate(int number){        return f(number);    }    static int f(int n){        int sum=0;        while(n>0){            sum+=n%10;            n=n/10;        }        return sum;    }    }

Draft At 8:06PM I ate and then started 10min back

using System;using System.Collections.Generic;using System.IO;

class Solution {    

static void Main(String[] args) {        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */       

 int total=int.Parse(Console.ReadLine());    
for(int i=0;i<total;i++){      
      int number=int.Parse(Console.ReadLine().Split(‘ ‘)[0]);         
   Console.WriteLine(calculate(number));  
      }    }    
static int calculate(int number){        return f(number);    }    
static int g(int n){        i=0;        
while(sf(f(n))!=sf(f(i))){            i++;        }        
return i;    }    
static int sigmat(int n){        
int sum=0;        
for(int i=1;i<=n;i++){            sum+=sg(i);        }    }    
static int sg(int n){        return sf(n);    }    
static int f(int n){        
int sum=0;        
while(n>0){            
int sumA=n%10;           
 int factorial=1;            
while(sumA>1){              factorial*=(sumA–);            }           
 sum+=factorial;            n=n/10;        }       
 return sum;    }   
 static int sf(int n){       
 int sum=0;         while(n>0){            sum+=n%10;            n=n/10;        }        
return sum;    }    }

sorry I should provide this in a code block mostly so it will look nicer next update I will do that.

Finally Solved with below code

using System;
using System.Collections.Generic;
using System.IO;
class Solution {
    static void Main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        int total=int.Parse(Console.ReadLine());
        for(int i=0;i<total;i++){
            string str=Console.ReadLine();
            int number=int.Parse(str.Split(‘ ‘)[0]);
            int m=int.Parse(str.Split(‘ ‘)[1]);
            Console.WriteLine(calculate(number)%m);
        }
    }
    static long calculate(int number){
        return sigmat(number);
    }
    static int g(int n){
        int i=0;
        while(sf(i)!=n){
            i++;
        }
        return i;
    }
    static long sigmat(int n){
        long sum=0;
        for(int i=1;i<=n;i++){
            sum+=sg(i);
        }
        return sum;
    }
    static int sg(int n){
        n=g(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    static int f(int n){
        int sum=0;
        while(n>0){
            int sumA=n%10;
            int factorial=1;
            while(sumA>1){
                factorial*=(sumA–);
            }
            sum+=factorial;
            n=n/10;
        }
        return sum;
    }
    static int sf(int n){
        n=f(n);
        int sum=0;
         while(n>0){
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
    
}
Design a site like this with WordPress.com
Get started