Tarsus skills

A. Competitive Programmer

The meaning of problems: a long numbers of permutations and combinations, whether referred to make it a multiple of 60.
Analysis: First, there must be a zero as a divisor of 10. 60 is converted to 6,6 * 3 = 2, if it can be divided by 2 as the number of bits as the divisor 2. 6 into 3, is a multiple of 3, it can be the sum of 3 integers.

Prove that a large number could be 3 integers:
for example, a number abc, we read as a one hundred ten b c, because on the one hundred, on ten, the last bit in a b c. I.e., 100 * a + 10 * b + c = 99 * a + a + 9 * b + b + c. We know that can be divisible by 3 9,99, and so 99 * a 9 * b can be divisible by 3, it is determined whether abc divisible Question 3, it is reduced to a + b + c determine whether divisible by 3! Here, we want to give the first important conclusion: to determine whether a number is divisible by 3, need only determine whether the sum of the numbers on each digit, and this number can be divisible by 3, and if divisible by 3, then the original number divisible by 3, and if not divisible by 3, then the remainder is the original number is divided by 3.

#include<bits/stdc++.h>
using namespace std;
char s[1000];
void solve(){
    cin>>s;
    int sum=0;
    int hasz=0,hast=0;
    for(int i=0;s[i];++i){
        sum=(sum+s[i]-'0')%3;
        if(s[i]-'0'==0&&hasz==0) hasz=1;
        else if((s[i]-'0')%2==0) hast=1;
    }
    if(sum==0&&hasz==1&&hast==1)cout<<"red"<<endl;
    else cout<<"cyan"<<endl;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Trailing Zeros

Problem: calculate the factorial of a number at the end of the number 0
Analysis: * 5 2 0 caused by, the quality factor factorial factorial with a plurality 2,5 factor. 2,5 may be combined with the number at the end is the number 0.

#include<bits/stdc++.h>
using namespace std;
int a[]={2,5};
long long cnt[]={0,0};
int main(){
    long long n;
    cin>>n;
    for(int i=0;i<2;++i){
        long long tmp=n;
        while(tmp){
            cnt[i]+=tmp/a[i];
            tmp/=a[i];
        }
    }
    cout<<min(cnt[0],cnt[1]);
    return 0;
}


Large numbers can be divisible decimal

Problems: A B can be an integer
Analysis: each A can be decomposed into n * B + C, C is the value of A% B, so we can think of a number can be prefixed modB, each time, the resulting C If the number is 0, then divisible, whether the person can not be divisible.

#include<bits/stdc++.h>
using namespace std;
char A[10105];
int B;
int main(){
    int res=0;
    scanf("%s",A);
    scanf("%d",&B);
    for(int i=0;A[i];i++){
        res*=10;
        res+=A[i]-'0';
        res%=B;
    }
    if(res==0) printf("Yes");
    else printf("No");
    return 0;
}
Published 96 original articles · won praise 11 · views 2269

Guess you like

Origin blog.csdn.net/weixin_43769146/article/details/103743055