uva12546. LCM Pair Sum
uva12546. LCM Pair Sum

In other words, he needs the sum of all possible pairs whose least common multiple is n. (The least common multiple (LCM) of two numbers p and q is the lowest positive integer which can be perfectly divided by both p and q). For example, there are 5 different pairs having their LCM equal to 6 as (1, 6), (2, 6), (2, 3), (3, 6), (6, 6). So f (6) is calculated as f (6) = (1 + 6) + (2 + 6) + (2 + 3) + (3 + 6) + (6 + 6) = 7 + 8 + 5 + 9 + 12 = 41.
Your friend knows you are good at solving this kind of problems, so he asked you to lend a hand. He also does not want to disturb you much, so to assist you he has factorized the number. He thinks it may help you.
Input
The first line of input will contain the number of test cases T (T500). After that there will be T test cases. Each of the test cases will start with a positive number C (C
15) denoting the number of prime factors of n. Then there will be C lines each containing two numbers Pi and ai denoting the prime factor and its power (Pi is a prime between 2 and 1000) and ( 1
ai
50). All the primes for an input case will be distinct.
Output
For each of the test cases produce one line of output denoting the case number and f (n) modulo 1000000007. See the output for sample input forexact formatting.
Sample Input
3
2
2 1
3 1
2
2 2
3 1
1
5 1
Sample Output
Case 1: 41
Case 2: 117
Case 3: 16
这道题目也也搞了很长时间,算是初识母函数吧,这道题目用到了这种思想。做完了,感觉还是不太明白怎么就能用
(1+a1+a1^2...(c1+1)*a1^c1)*(1+a2+a2^2...(c2+1)*a2^c2)*.....*(1+am+am^2...(cm+1)*am^cm)+n 这个公式。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD = ; int main() {
int TCase;
cin >> TCase;
for(int t = ; t <= TCase; ++t) {
long long n, p, c;
long long ans = , flag = ;
cin >> n;
for(int i = ; i != n; ++i) {
long long tmp = , fac = ;
cin >> p >> c;
for(int j = ; j != c; ++j) {
fac = (fac * p) % MOD;
tmp = (tmp + fac) % MOD;
}
tmp = (tmp + (fac * c) % MOD) % MOD;
flag = (fac * flag) % MOD;
ans = (ans * tmp) % MOD;
}
ans = (ans + flag) % MOD;
cout << "Case " << t << ": " << ans << endl;
}
return ;
}
uva12546. LCM Pair Sum的更多相关文章
- bzoj3114 LCM Pair Sum
题意:以质因数分解的方式给定n,求所有满足:lcm(a, b) = n的无序数对的价值和.其中(a, b)的价值为a + b 解: 定义首项为a,公比为q,项数为n的等比数列的和为getQ(a, q, ...
- light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum
第一题给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em, 则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2. 代码如下: #include <st ...
- UVA12546_LCM Pair Sum
题目的意思是求 [西伽马(p+q)]其中lcm(p,q)=n. 又见数论呀. 其实这个题目很简单,考虑清楚了可以很简单的方法飘过. 我一开始是这样来考虑的. 对于每一个单独的质因子,如果为p,它的次数 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Subarray Sum Closest
Question Given an integer array, find a subarray with sum closest to zero. Return the indexes of the ...
- LeetCode 1099. Two Sum Less Than K
原题链接在这里:https://leetcode.com/problems/two-sum-less-than-k/ 题目: Given an array A of integers and inte ...
- [LC] 1099. Two Sum Less Than K
Given an array A of integers and integer K, return the maximum S such that there exists i < j wit ...
- 【LeetCode】1099. Two Sum Less Than K 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力求解 日期 题目地址:https://leetco ...
- Java中的泛型 (上) - 基本概念和原理
本节我们主要来介绍泛型的基本概念和原理 后续章节我们会介绍各种容器类,容器类可以说是日常程序开发中天天用到的,没有容器类,难以想象能开发什么真正有用的程序.而容器类是基于泛型的,不理解泛型,我们就难以 ...
随机推荐
- 搭建FTP服务器
yum install vsftpd -yyum install pam* db4* --skip-broken –y 创建并生成vsftpd 数据库文件vi /etc/vsftpd/ftpusers ...
- thinkphp 导出exl功能
/** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@p ...
- IHttpModule生命周期
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- [Head First设计模式]抢票中的设计模式——代理模式
系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...
- 都别说工资低了,我们来一起写简单的dom选择器吧!
前言 我师父(http://www.cnblogs.com/aaronjs/)说应当阅读框架(jquery),所以老夫就准备开始看了 然后公司的师兄原来写了个dom选择器,感觉不错啊!!!原来自己从来 ...
- java读取项目根路径下和任意磁盘位置下的properties文件
1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties ...
- LInux升级Python版本2.7.11所遇问题汇总
首先请原谅我使用校园网络,基本上打不开谷歌,网络搜取得帮助均来自度娘. 对于我这个linux新手 IT 新手来说,自己升级点东西好担心,万一出错,可能都要重来.... 参照度娘内容和自己摸索,今天晚上 ...
- Javascript实现图片预加载【回调函数,多张图片】
使用JS实现一组图片动画效果或者使用HTML5 Canvas渲染一系列图片等案例中,需要图片全部加载完成方可运行动画效果.此时程序中就会涉及多张图片预加载代码.当接二连三的案例中都涉及图片预加载时,就 ...
- Burpsuite+sqlmap批量扫描sql漏洞
1.burpsuite设置导出log n'd'k 输入文件名保存 2.sqlmap批量扫描 python sqlmap.py -l 文件名 --batch -smart batch:自 ...
- 示例开发过程记录:meteor,react,apollo
本示例记录一个开发过程: 1)参考 Meteor React TUTORIAL教程 https://www.meteor.com/tutorials/react/creating-an-app 2). ...