Check if a large number is divisible by 3 or not
Posted chuanwen-tech
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于Check if a large number is divisible by 3 or not的主要内容,如果未能解决你的问题,请参考以下文章
如何检查数字是浮点数还是整数? - How do I check that a number is float or integer?
python 来自http://stackoverflow.com/questions/4188326/in-python-how-do-i-check-if-a-drive-exists-w-o-t
LeetCode --- 1232. Check If It Is a Straight Line 解题报告
LeetCode --- 1232. Check If It Is a Straight Line 解题报告