AtCoder Regular Contest 091

数学场,做到怀疑人生系列

C - Flip,Flip, and Flip......


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.

We will perform the following operation once for each square contains a card:

  • For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.

It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Constraints

  • 1≤N,M≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of cards that face down after all the operations.


Sample Input 1

Copy
2 2

Sample Output 1

Copy
0

We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.


Sample Input 2

Copy
1 7

Sample Output 2

Copy
5

After all the operations, all cards except at both ends face down.


Sample Input 3

Copy
314 1592

Sample Output 3

Copy
496080

这个可以找规律,314×5×k的末尾是0 ,然后不断找下去,竟然是这个数-2相乘

#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
    cin>>a>>b;
    cout<<abs((a-2)*(b-2));
}

D - Remainder Reminder


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

Takahashi had a pair of two positive integers not exceeding N(a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.

Constraints

  • 1≤N≤105
  • 0≤KN−1
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of possible pairs that he may have had.


Sample Input 1

Copy
5 2

Sample Output 1

Copy
7

There are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).


Sample Input 2

Copy
10 0

Sample Output 2

Copy
100

Sample Input 3

Copy
31415 9265

Sample Output 3

Copy
287927211

 这个题目骚啊,去暴力统计每个值对应的方案

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    long long ans=0;
    for(int i=k+1; i<=n; i++)
        ans+=(n/i)*1LL*(i-k)+max(n%i-k+1,0)-!k;
    cout<<ans;
}

 

posted @ 2018-03-15 06:42  暴力都不会的蒟蒻  阅读(493)  评论(0编辑  收藏  举报