设为首页 加入收藏

TOP

Codeforces Round #272 (Div. 2)(二)
2015-07-20 17:29:58 来源: 作者: 【 】 浏览:7
Tags:Codeforces Round #272 Div.
0; for(int i=0;i wh) { printf(0 ); return 0; } pneed = (temp + wh) / 2; mneed = wh - pneed; int ans = 1; for(int i = 0; i < pneed; i++) { ans *= wh; --wh; } for(int i=1; i<= pneed; i++) ans /= i; printf(%.12f ,double(ans)/double(all)); }


?

?

?

?

C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes

Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if align=middle and align=middle, where k is some integer number in range [1,?a].

By align=middle we denote the quotient of integer division of x and y. By align=middle we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.

The answer may be large, so please print its remainder modulo 1?000?000?007 (109?+?7). Can you compute it faster than Dreamoon?

Input

The single line of the input contains two integers a, b (1?≤?a,?b?≤?107).

Output

Print a single integer representing the answer modulo 1?000?000?007 (109?+?7).

Sample test(s) Input
1 1
Output
0
Input
2 2
Output
8
Note

For the first sample, there are no nice integers because align=middle is always zero.

For the second sample, the set of nice integers is {3,?5}.

?

?

?

#include 
   
     #define ll long long const int mod=1e9 + 7; int main() { ll a,b; scanf(%I64d %I64d, &a, &b); if(b == 1) printf(0 ); else { ll res = (b * (b - 1) / 2) % mod; ll sum = (a * (a + 1) / 2) % mod; ll ans = (a % mod * res % mod) % mod; ll temp = (sum % mod * res % mod) % mod; printf(%I64d , (ans % mod + (temp % mod * b % mod)) % mod); } }
   


?

?

?

?

D. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes

Dreamoon likes to play with sets, integers and align=middle. align=middle is defined as the largest positive integer that divides both a and b.

Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, align=middle.

Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.

Input

The single line of the input contains two space separated integers n, k (1?≤?n?≤?10?000,?1?≤?k?≤?100).

Output

On the first line print a single integer — the minimal possible m.

On each of the next n lines print four space separated integers representing the i-th set.

Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.

Sample test(s) Input
1 1
Output
5
1 2 3 5
Input
2 2
Output
22
2 4 6 22
14 18 10 16
Note

For the first example it's easy to see that set {1,?2,?3,?4} isn't a valid set of rank 1 since align=middle.

?

?

#include 
   
     int main() { int n, k; scanf(%d %d, &n, &k); int a = 1, b = 2, c = 3, d = 5; printf(%d , (d * k + 6 * k * (n- 1))); a *= k; b *= k; c *= k; d *= k; for(int i = 0; i < n; i++) { printf(%d %d %d %d ,a, b, c, d); a += 6 * k; b += 6 * k; c += 6 * k; d += 6 * k; } }
   

?


?

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇NYoj-5个数求最值 下一篇ZOJ - 3822 Domination (DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)
·Redis - The Real-ti (2025-12-26 08:20:50)
·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)