1576

const int mod = 9973;

n = a - a / mod * mod;

a / b = ans;

ans * b = a = a / mod * mod + n;

n = b * ans - a / mod * mod;

n = b * ans + mod * y;

extended_gcd(b, mod, ans, y);

 #define PRON "hdu1576"
#define LL "%lld"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int MOD = ; int Tcase; ll extended_gcd(ll a, ll b, ll & x, ll & y){
if (b == ){
x = , y = ;
return a;
} ll d = extended_gcd(b, a % b, x, y);
ll temp = x;
x = y;
y = temp - a / b * y; return d;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif ll a, b, x, y; scanf("%d", &Tcase);
while (Tcase --){
scanf(LL LL, &a, &b);
extended_gcd(b, MOD, x, y);
x = ((x * a % MOD) + MOD) % MOD;
printf(LL "\n", x);
}
}

hdu1576

2824

Σphi[i]

 #define PRON "hdu2824"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; const int MAXN = ; int n, m;
ll phi[MAXN + ]; void get_phi(){
memset(phi, , sizeof phi);
phi[] = ;
for (int i = ; i <= MAXN; i ++)
if (!phi[i]){
for (int j = i; j <= MAXN; j += i){
if (!phi[j])
phi[j] = j;
phi[j] = phi[j] / i * (i - );
}
}
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif get_phi();
for (int i = ; i <= MAXN; i ++)
phi[i] += phi[i - ]; while (scanf("%d %d", &n, &m) == )
cout << phi[m] - phi[n - ] << endl;
}

hdu2824

1573

中国剩余定理的一般形式

 #define PRON "hdu1573"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef int ll; const int MAXN = + ; int Tcase, _max, n, a[MAXN], b[MAXN]; ll extended_gcd(ll a, ll b, ll & x, ll & y){
if (b == ){
x = , y = ;
return a;
} ll d = extended_gcd(b, a % b, x, y);
ll temp = x;
x = y;
y = temp - a / b * y; return d;
} ll normal_crt(){
ll m1, m2, r1, r2, x, y; //solve N = r1 (mod m1)
// N = r2 (mod m2)
m1 = a[], r1 = b[];
for (int i = ; i < n; i ++){
m2 = a[i], r2 = b[i]; //solve d = x * m1 + y * m2
//(x, y) is the solution to the equation above
//solve c = r2 - r1 = y * m2 - x * m1
//(x0, y0) is the solution to the equation above
//x0 = x * c / d, y0 = x * c / d
ll d = extended_gcd(m1, m2, x, y);
ll c = r2 - r1;
if (c % d)
return ; ll t = m2 / d;
x = (x * c / d % t + t) % t; //r1 is the solution to the equaions from 1st to ith
r1 += m1 * x;
//m1 is the lcm of m1 to mi
m1 *= t;
} if (_max < r1)
return ; //if (x0, y0) is one of the solution
//(x0 + k * m2 / d, y0 - k * m1 / d) (k -> Z) also apply
return (_max - r1) / m1 + - (bool)(r1 == );
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &Tcase);
while (Tcase --){
scanf("%d %d", &_max, &n);
for (int i = ; i < n; i ++)
scanf("%d", a + i);
for (int i = ; i < n; i ++)
scanf("%d", b + i); printf("%d\n", normal_crt());
}
}

1573

1370

中国剩余定理

 #define PRON "hdu1370"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef int ll; const int MAXN = ;
const int MOD = ; int Tcase, cnt, st, a[MAXN], b[MAXN]; ll extended_gcd(ll a, ll b, ll & x, ll & y){
if (b == ){
x = , y = ;
return a;
} ll d = extended_gcd(b, a % b, x, y);
ll temp = x;
x = y;
y = temp - a / b * y; return d;
} ll inv(ll a, ll n){
ll x, y;
ll d = extended_gcd(a, n, x, y);
return d == ? (x + n) % n : -;
} ll crt(int n){
ll ret = , m = ; for (int i = ; i < n; i ++)
a[i] %= b[i], m *= b[i]; for (int i = ; i < n; i ++)
ret = (ret + a[i] * (m / b[i]) * inv(m / b[i], b[i])) % m; ret -= st;
return ret + MOD * (bool)(ret <= );
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cnt = ;
b[] = , b[] = , b[] = ; scanf("%d", &Tcase);
while (scanf("%d %d %d %d", &a[], &a[], &a[], &st) == && !(a[] == - && a[] == - && a[] == -))
printf("Case %d: the next triple peak occurs in %d days.\n", ++ cnt, crt());
}

1370

HDU Math Problems的更多相关文章

  1. hdu some problems in Multi-University Training Contest

    hdu 6103 Kirinriki #include<bits/stdc++.h> using namespace std; int n,m,ans; ]; void doit(int ...

  2. Simple Math Problems

    整理下<算法笔记>,方便查看. 一.最大公约数&最小公倍数 欧几里得定理:设a,b均为正整数,那么gcd(a,b)=gcd(b,a%b). 若,定理就先交换a和b. 注意:0和任意 ...

  3. HDU 1220 Cube(数学,找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  6. HDU 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  7. hdu 1085 Holding Bin-Laden Captive!

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  8. HDU 1085-Holding Bin-Laden Captive!(生成功能)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  9. HUST 1555 A Math Homework

    1555 - A Math Homework 时间限制:1秒 内存限制:128兆 338 次提交 131 次通过 题目描述     QKL is a poor and busy guy, and he ...

随机推荐

  1. php设计模式之单例模式使用示例

    单例模式也就是只能实例化一次,也就代表在实例化时不可能使用new关键字,下面是使用示例,大家参考使用吧   <?php class EasyFramework_Easy_Mysql{     p ...

  2. VC++中StretchBlt图像失真问题的解决办法

    在 VC 中使用 StretchBlt 会碰到一些与点阵图大小缩放相关的一些问题.在扩展一个点阵图时,StretchBlt必须复制图素行或列.如果放大倍数不是原图的整数倍,那么此操作会造成产生的图像有 ...

  3. Flex 对象克隆

    package widget.EnvPlot{ public class copyObject extends Object    {        public function copyObjec ...

  4. SOA架构介绍和理解

    SOA架构介绍和理解 SOA的正确方法论及目标模型,其实SOA在实现架构落地上,需要考虑到对服务的组合,不断的重用现有的服务,让企业应用可以逐步集成,快速实现业务的迭代. 通过SOA架构分层将服务按照 ...

  5. String 与 StringBuffer的区别

    String="a" 的方式每相加一次就创建一个新的常量,原常量不消失,比较占内存:StringBuffer是放在堆里面,append直接在原地址相加,不占内存

  6. 未能正确加载“RoslynPackage”包

    一打开新建程序或者打开项目就报错,原因是安装的组件或者模板丢失或者有问题,在这一过程加载组件必定会产生错误,以下为解决方法: 1.重命名以下文件夹C:\Users\moonlight\Local Se ...

  7. XML约束之DTD

    XML文件的约束:什么叫约束呢?顾名思义,就是对xml文件的内容进行按照既定规则的限制.我们知道,因为xml文件的标签是可以自定义的,而往往我们用xml文件都是为了表达一定的数据集合(即小型的数据库) ...

  8. easyui 中datagrid 点击行的事件

    $('#datagrid 的ID').datagrid({                onClickRow:function(index,data)                {        ...

  9. 总结A*,Dijkstra,广度优先搜索,深度优先搜索的复杂度比较

    广度优先搜索(BFS) 1.将头结点放入队列Q中 2.while Q!=空 u出队 遍历u的邻接表中的每个节点v 将v插入队列中 当使用无向图的邻接表时,复杂度为O(V^2) 当使用有向图的邻接表时, ...

  10. 做webapp静态页面的一些积累

    ​1)根据pad,手机不同的版本的屏幕大小设置字体的大小(可以使用此方式根据屏幕的不同进行设置,由于我左边的图片是设置的float='left',使用的是img标签的百分比来显示图片) (使用此方式, ...