OpenJudge exercises and answers (C ++) -- question 4045: numbers irrelevant to 3 and 5

Source: Internet
Author: User

OpenJudge exercises and answers (C ++) -- question 4045: numbers irrelevant to 3 and 5
Question:

Total time limit:
1000 ms
Memory limit:
65536kB
Description

A positive integer. If it can be divisible by x, or the number in a single digit in its decimal representation is x, it is called the number related to x. calculate the sum of the squares of all positive integers less than or equal to n (n <300) that are irrelevant to x.

Input
Input is a row, positive integer n, (n <300)
Output
The sum of squares of positive integers 3 and 5 that are less than or equal to n
Sample input:
8
Sample output:
134
Solution:
#include<iostream>using namespace std;int main(){int n;cin>>n;int s=0;if (n<10){for(int i=1;i<=n;i++){if(i%3!=0&&i%5!=0&&i!=3&&i!=5){s+=i*i;}}}else if(n<100){for(int i=1;i<=n;i++){if(i%5!=0&&i%3!=0&&i/10!=3&&i/10!=5&&i%10!=3&&i%10!=5){s+=i*i;}}}else{for(int i=1;i<=n;i++){if(i%5!=0&&i%3!=0){if(i/100!=5&&i/100!=3&&i%10!=3&&i%10!=5&&i%100/10!=3&&i%100/10!=5){s+=i*i;}}}}cout<<s; return="" pre=""><p></p>   </s;></iostream>

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.