Problem:
-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
-
Describe
-
-
A positive integer, if it can be divisible by x, or its decimal notation is x on a single digit, it is called an X-related number. Now we seek the sum of squares of all positive integers that are less than or equal to N (n<300) and that are not X-independent.
-
-
Input
-
-
input is a row, positive integer n, (n<300)
-
-
Output
-
-
outputs the sum of squares of positive integers that are less than or equal to N and are unrelated to 3 and 5
-
-
Sample input:
-
-
8
-
-
Sample output:
-
-
134
Solution:
#include<iostream>using namespaceStd;int Main(){intN;Cin>>N;intS=0;if (N<Ten){ for(intI=1;I<=N;I++){if(I%3!=0&&I%5!=0&&I!=3&&I!=5){S+=I*I;}}}Else if(N< -){ for(intI=1;I<=N;I++){if(I%5!=0&&I%3!=0&&I/Ten!=3&&I/Ten!=5&&I%Ten!=3&&I%Ten!=5){S+=I*I;}}}Else{ for(intI=1;I<=N;I++){if(I%5!=0&&I%3!=0){if(I/ -!=5&&I/ -!=3&&I%Ten!=3&&I%Ten!=5&&I% -/Ten!=3&&I% -/Ten!=5){S+=I*I;}}}}cout<<S;return 0;}
Openjudge Exercise Solution (c + +)-Question 4045: numbers unrelated to 3 and 5