Why does this not output anything?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cmath>
int main(){
    int casos=0;
    std::cin>>casos;
    int num=0;
    int num1=0;
    int result=0;
    for(int n=0;n<casos;n++){
    std::cin>>num;
    num1=num;
    int a=1;
    while(1){
        num1=num*a;
    result=sqrt(num1);
    if((result%10)*(result%10)==num){
        std::cout<<a<<"\n";
        break;
    }else{
        a++;
    }
    
    }
    
    
}
}


I want to check, which is the smallest number a, which I have to multiply to a certain number, so that the result of it is a square number
Learn to properly format your code.
It looks like garbage.

Your problem description doesn't make much sense and doesn't correspond to your code.
Since this is from some kind of problem/challenge site you should post the link so we can read the original problem.
Last edited on
Fixed. Just type in 1 at the prompt (or lack thereof) then 1 again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <cmath>

int main(){
    int casos=0;
    std::cin>>casos;
    int num=0;
    int num1=0;
    int result=0;
    for(int n=0;n<casos;n++)
    {
        std::cin>>num;
        num1=num;
        int a=1;
        while(1)
        {
            num1=num*a;
            result=sqrt(num1);
            std::cout << "yabi2943993 is a fuckwit ";
            if((result%10)*(result%10)==num)
            {
                std::cout<<a<<"\n";
                break;
            }
            else
            {
                a++;
            }
            
        }
    }
}
> (result%10)*(result%10)==num
¿?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

//============================

int makeSquare( int n )           // Find prime factors; if there is an odd number of any factor .. you need that factor
{
   int multiplier = 1;
   int kmax = sqrt( n ) + 1;
   bool isPrime = true;

   // Factors of 2
   bool yes = false;
   while ( n % 2 == 0 )           
   {
      n /= 2;
      yes = !yes;
      isPrime = false;
   }
   if ( yes ) multiplier *= 2;
   
   // Odd factors
   int k = 3;                     
   yes = false;
   while ( n > 1 )
   {
      if ( n % k != 0 )           // If not a factor, move to next odd number (otherwise test again)
      {
         if ( yes ) multiplier *= k;
         k += 2;                  
         yes = false;      
      }
      else                        // Remove this prime factor before continuing
      {
         n /= k;
         yes = !yes;
         isPrime = false;                  
      }

      if ( k >= kmax && isPrime ) break;         // Got this far ... no chance of finding non-trivial factors
   }
   if ( yes ) multiplier *= k;

   if ( isPrime ) multiplier *= n;

   return multiplier;
}

//============================

int main()
{
   for ( int n = 1; n <= 40; n++ )
   {
      int multiplier = makeSquare( n );
      int root = sqrt( n * multiplier + 0.5 );
      cout << n << " * " << multiplier << " = " << n * multiplier;
      cout << "   ( " << root << " * " << root << " = " << root * root << " )\n";
//    cout << multiplier * n - root * root << '\n';
   }
}

//============================ 



1 * 1 = 1   ( 1 * 1 = 1 )
2 * 2 = 4   ( 2 * 2 = 4 )
3 * 3 = 9   ( 3 * 3 = 9 )
4 * 1 = 4   ( 2 * 2 = 4 )
5 * 5 = 25   ( 5 * 5 = 25 )
6 * 6 = 36   ( 6 * 6 = 36 )
7 * 7 = 49   ( 7 * 7 = 49 )
8 * 2 = 16   ( 4 * 4 = 16 )
9 * 1 = 9   ( 3 * 3 = 9 )
10 * 10 = 100   ( 10 * 10 = 100 )
11 * 11 = 121   ( 11 * 11 = 121 )
12 * 3 = 36   ( 6 * 6 = 36 )
13 * 13 = 169   ( 13 * 13 = 169 )
14 * 14 = 196   ( 14 * 14 = 196 )
15 * 15 = 225   ( 15 * 15 = 225 )
16 * 1 = 16   ( 4 * 4 = 16 )
17 * 17 = 289   ( 17 * 17 = 289 )
18 * 2 = 36   ( 6 * 6 = 36 )
19 * 19 = 361   ( 19 * 19 = 361 )
20 * 5 = 100   ( 10 * 10 = 100 )
21 * 21 = 441   ( 21 * 21 = 441 )
22 * 22 = 484   ( 22 * 22 = 484 )
23 * 23 = 529   ( 23 * 23 = 529 )
24 * 6 = 144   ( 12 * 12 = 144 )
25 * 1 = 25   ( 5 * 5 = 25 )
26 * 26 = 676   ( 26 * 26 = 676 )
27 * 3 = 81   ( 9 * 9 = 81 )
28 * 7 = 196   ( 14 * 14 = 196 )
29 * 29 = 841   ( 29 * 29 = 841 )
30 * 30 = 900   ( 30 * 30 = 900 )
31 * 31 = 961   ( 31 * 31 = 961 )
32 * 2 = 64   ( 8 * 8 = 64 )
33 * 33 = 1089   ( 33 * 33 = 1089 )
34 * 34 = 1156   ( 34 * 34 = 1156 )
35 * 35 = 1225   ( 35 * 35 = 1225 )
36 * 1 = 36   ( 6 * 6 = 36 )
37 * 37 = 1369   ( 37 * 37 = 1369 )
38 * 38 = 1444   ( 38 * 38 = 1444 )
39 * 39 = 1521   ( 39 * 39 = 1521 )
40 * 10 = 400   ( 20 * 20 = 400 )
Topic archived. No new replies allowed.