ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1118. Nontrivial Numbers

The time limit
Posted by Savchuk Nickolay 23 Mar 2021 17:29
Good afternoon! I am a programmer-beginner. I have written the code for this task on c++, but the time limit is exceeded on the second test!
The code is this: (https://ideone.com/Rh98zQ)

#include <iostream>
using namespace std;

float ghj(int a)
{int m;
m=0;
for(int l=1; l<a; l++)
{if(a%l==0)
{m=m+l;}}
float c=(float(int(m)));
float b=c/a;
return b;}

int main() {
int i,j;
cin >> i >> j;
float p=ghj(i);
int n=i;
for(int o=i; o<=j; o++)
{if(ghj(o)<p)
{p=ghj(o);
n=o;}}
cout << n;
return 0;
}

Tell me, please, how can I optimize the code?