Check if a large number is divisible by 3 or not

 1 //检验一个大数是否能3整除
 2 //A number is divisible by 3 if sum of its digits is divisible by 3.
 3 //we cannot use n % 3 to check if a number is divisible by 3 or not.
 4 //Remainder of 10i divided by 3 is 1 So powers of 10 only result in value 1.
 5 #include<bits/stdc++.h>
 6 using namespace std;
 7
 8 int main()
 9 {
10     string s;
11     cin>>s;
12     int len=s.length();
13     int sum=0;
14     for(int i=0;i<len;i++)
15     {
16         sum+=s[i]-‘0‘;
17     }
18     if(sum%3==0)
19         cout<<"yes"<<endl;
20     else
21         cout<<"no"<<endl;
22     return 0;
23 }
1 # “脱数“代码
2 def check(num):
3     while num>0:
4         rem=num%10
5         sum+=rem
6         num/=10

原文地址:https://www.cnblogs.com/chuanwen-tech/p/11296178.html

时间: 2024-10-29 19:52:00

Check if a large number is divisible by 3 or not的相关文章

15 Linux Split and Join Command Examples to Manage Large Files--reference

by HIMANSHU ARORA on OCTOBER 16, 2012 http://www.thegeekstuff.com/2012/10/15-linux-split-and-join-command-examples-to-manage-large-files/ Linux split and join commands are very helpful when you are manipulating large files. This article explains how

Diesel-engined definitely appreciates that your great gals check out

Many people are prone to possibly be known. However for these with premium quality, many people glimpse pretty much identical while using the originals having just about every aspect thoroughly made. Because of the primary perception, there're simply

Leetcode 202. Happy Number

202. Happy Number Total Accepted: 78171 Total Submissions: 208635 Difficulty: Easy Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace t

LeetCode-Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty

LeetCode——Ugly Number

Description: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note

Leetcode 263. Ugly Number JAVA语言

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty

Leetcode 263. Ugly Number

263. Ugly Number Total Accepted: 65061 Total Submissions:173755 Difficulty: Easy Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly

LeetCode263——Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7. Note that 1 is ty

Lettcode_263_Ugly Number

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49431329 Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly wh