682A - Alyona and Numbers - CodeForces Solution


constructive algorithms math number theory *1100

Please click on ads to support us..

Python Code:

def fun(d,ubound):
    c = int(.1*ubound)
    if(d!=0 and ubound%10>=d):
        c+=1
    return c
n,m = map(int,input().split(' '))
count = 0
for a in range(0,10):
    b = 10-a
    if(b==10):b=0
    c1= fun(a,n)
    c2= fun(b,m)
    count += c1*c2
    if(a<=5):
        b2=5-a
    else:
        b2=15-a
    c3=fun(b2,m)
    count+= c1*c3
print(count)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;

void solve(int n,int m)
{
    int freq1[5]={0,0,0,0,0};
    int freq2[5]={0,0,0,0,0};
    for(int i=1;i<=n;i++)
    {
        int rem=i%5;
        freq1[rem]++;
    }
    for(int i=1;i<=m;i++)
    {
        int rem=i%5;
        freq2[rem]++;
    }
    int ans=freq1[0]*freq2[0]+freq1[1]*freq2[4]+freq1[2]*freq2[3]+freq1[3]*freq2[2]+freq1[4]*freq2[1];
    cout<<ans<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    solve(n,m);
}


Comments

Submit
0 Comments
More Questions

42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility