Openjudge Exercise Solution (c + +)-Question 4045: numbers unrelated to 3 and 5

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.