+0  
 
0
498
2
avatar

Find the number of positive integers less than 1000 that are not square, not even, and not divisible by 5.

 May 15, 2020
 #1
avatar
0

a=0;b=0;c=1;p=0; cycle:d=a*100+b*10+c;if(d%2==1 and d%5!=0 and d% 2#d !=0, goto loop, goto next); loop:printd," ",;p=p+1; next:c++;if(c<10, goto cycle, 0);c=1;b++;if(b<10, goto cycle, 0);b=0;c=1;a++;if(a<10, goto cycle,0);print"Total = ",p

 

OUTPUT = 388 such numbers, which includes 1 and 999

 May 15, 2020
 #2
avatar+2446 
+1

I did this same exercise, and I got 387!

 

If you are curious about the code I wrote, then here you go:

public static void main(String[] args)
    {
        int numPassed = 0;
        int numToTest = 0;
        double temp = 0.0;
        for (int hundredDigit = 0; hundredDigit<=9; hundredDigit++)
        {
            for (int tenDigit = 0; tenDigit<=9; tenDigit++)
            {
                for (int oneDigit = 0; oneDigit<=9; oneDigit++)
                {
                    numToTest = hundredDigit*100+tenDigit*10+oneDigit;
                    temp = Math.sqrt((double) numToTest);
                    if (temp != Math.floor(temp) && numToTest%2==1 && numToTest%5!=0)
                    {
                        System.out.println(numToTest);
                        numPassed++;
                    }
                }
            }
        }
        System.out.println(numPassed);
    }

 

Here is the list, if you are curious: 3,7,11,13,17,19,21,23,27,29,31,33,37,39,41,43,47,51,53,57,59,61,63,67,69,71,73,77,79,83,87,89,91,93,97,99,101,103,107,109,111,113,117,119,123,127,129,131,133,137,139,141,143,147,149,151,153,157,159,161,163,167,171,173,177,179,181,183,187,189,191,193,197,199,201,203,207,209,211,213,217,219,221,223,227,229,231,233,237,239,241,243,247,249,251,253,257,259,261,263,267,269,271,273,277,279,281,283,287,291,293,297,299,301,303,307,309,311,313,317,319,321,323,327,329,331,333,337,339,341,343,347,349,351,353,357,359,363,367,369,371,373,377,379,381,383,387,389,391,393,397,399,401,403,407,409,411,413,417,419,421,423,427,429,431,433,437,439,443,447,449,451,453,457,459,461,463,467,469,471,473,477,479,481,483,487,489,491,493,497,499,501,503,507,509,511,513,517,519,521,523,527,531,533,537,539,541,543,547,549,551,553,557,559,561,563,567,569,571,573,577,579,581,583,587,589,591,593,597,599,601,603,607,609,611,613,617,619,621,623,627,629,631,633,637,639,641,643,647,649,651,653,657,659,661,663,667,669,671,673,677,679,681,683,687,689,691,693,697,699,701,703,707,709,711,713,717,719,721,723,727,731,733,737,739,741,743,747,749,751,753,757,759,761,763,767,769,771,773,777,779,781,783,787,789,791,793,797,799,801,803,807,809,811,813,817,819,821,823,827,829,831,833,837,839,843,847,849,851,853,857,859,861,863,867,869,871,873,877,879,881,883,887,889,891,893,897,899,901,903,907,909,911,913,917,919,921,923,927,929,931,933,937,939,941,943,947,949,951,953,957,959,963,967,969,971,973,977,979,981,983,987,989,991,993,997,999

 

I assume the discrepancy occurred because Guest included 1, which should not be included because it is a square number.

 May 15, 2020
edited by TheXSquaredFactor  May 16, 2020

1 Online Users