. Number throry
steve 学完了快速幂,现在会他快速的计算:(ij)%d , Alex 作为一个数学大师,给了 steve 一个问题:已知
i∈[1,n],j∈[1,m] ,计算满足 (ij)%d=0 的 (i,j) 的对数。
输入格式
T组输入,对于每一组输入三个数n,m,d。
(1≤T≤1000,1≤n,m,d≤109)。
输出格式
对于每组输入,输出答案,每个答案占一行。
样例
4
3 10 7
3 5 3
10 30 6
100 100 8
0
5
30
4937
不太懂,,先记下来再说
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b){
ll ans=;
while(b){
if(b&) ans=(ans*a);
a=(a*a);
b>>=;
}
return ans;
}
int main(){
int T;scanf("%d",&T);
while(T--){
ll n,m,d;
scanf("%lld %lld %lld",&n,&m,&d);
vector<pair<ll,ll> > prs;
vector<pair<ll,ll> >::iterator it;
for(ll i=;i*i<=d;i++){
if(d%i==){
long long cnt=;
while(d%i==){
d/=i;cnt++;
}
prs.push_back({i,cnt});
}
}
ll res=;
if(d!=) prs.push_back({d,});
for(ll j=;j<=min(m,1LL*);j++){
ll g=;
// for(auto v:prs)
for(it=prs.begin();it!=prs.end();it++)
{
g*=qpow( it->first,( it->second+j-)/j);
}
if(j==) res+=(m-)*(n/g);
else res+=n/g;
}
printf("%lld\n",res);
}
return ;
}
. Number throry的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- 动态规划-Minimum Insertion Steps to Make a String Palindrome
2020-01-05 11:52:40 问题描述: 问题求解: 好像多次碰到类似的lcs的变种题了,都是套上了回文的壳.这里再次记录一下. 其实本质就是裸的lcs,就出结果了. public int ...
- CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】
A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Spring05——Spring 如何实现事务管理
在此之前,我们已经了解了 Spring 相关的基础知识,今天将为给位带来,有关 Spring 事务代理的相关知识.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识 ...
- Linux命令ip addr详解
熟悉Linux操作系统的同学对于ip addr命令应该不陌生,知道它是用来查看本地IP地址的,除了IP地址,其它额外的信息有必要了解一下. root@test:~# ip addr1: lo: < ...
- POJ 1062 昂贵的聘礼 最短路+超级源点
Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...
- Keras 多层感知机 多类别的 softmax 分类模型代码
Multilayer Perceptron (MLP) for multi-class softmax classification: from keras.models import Sequent ...
- 干货 | Python进阶系列之学习笔记(二)
目录 对象 字符串 一.对象 (1)什么是对象 在python中一切都是对象,每个对象都有三个属性分别是,(id)身份,就是在内存中的地址,类型(type),是int.字符.字典(dic).列表(li ...
- ||,&&短路规则测试
短路规则:a||b中若a为真,则直接判断整个表达式为真,不再判断b是真或假, a&&b中若a为假,则直接判断整个表达式为假,不再单独判断b是真或假. 想要测试这个规则的话,可以将 ...
- elasticsearch在linux上的安装,Centos7.X elasticsearch 7.6.2
本文环境:Elasticsearch7.6.2目前最先版本 centos7.X JDK1.8 elasticsearch介绍 官网:https://www.elastic.co/cn/pr ...
- Linux yum 源配置
CentOS 7 使用 163 的 yum 源,配置步骤如下: 下载镜像源文件 http://mirrors.163.com/.help/centos.html 备份原配置文件,将下载的文件的名字改成 ...