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;
    }
    
}

Leave a comment

Design a site like this with WordPress.com
Get started