Can you find it

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5478

Description

Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109). Please find all pairs (a, b) which satisfied the equation ak1⋅n+b1 + bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...).

Input

There are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.

Output

First, please output "Case #k: ", k is the number of test case. See sample output for more detail.
Please output all pairs (a, b) in lexicographical order. (1≤a,b<C). If there is not a pair (a, b), please output -1.

Sample Input

23 1 1 2

Sample Output

Case #1:
1 22

HINT

题意

问你有多少对数,满足a^(k1⋅n+b1) + b^(k2⋅n−k2+1) = 0 (mod C)

题解:

首先你要知道,对于每个a只有唯一对应的b可以满足这个式子,因为当n=1的时候,a^(k1+b1)+b = kk*C

由于b是小于c的,所以只有一个

所以我们可以求出b来,然后我们怎么check这个b究竟是不是呢?

随机化10个数,然后随便check就好了

代码:

//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100006
#define mod 1000000007
#define eps 1e-9
#define e exp(1.0)
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* ll fMul(int m,ll n,int k)
{
ll cc = m;
ll b = ;
while (n > )
{
if (n & 1LL)
{
b = (b*cc);
if(b>=k)
b%=k;
}
n = n >> 1LL ;
cc = (cc*cc)%k;
if(cc>=k)cc%=k;
}
return b;
}
int main()
{
//freopen("out.txt","r",stdin);
//freopen("out2.txt","w",stdout);
srand(time(NULL));
int tot = ;
int c ,k1 ,b1 ,k2;
while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF)
{
printf("Case #%d:\n",tot++);
int flag1 = ;
for(int i=;i<c;i++)
{
int j=c-fMul(i,k1*+b1,c);
int flag = ;
for(int k=;k<=;k++)
{
ll tt = rand()%c+;
ll ttt1 = k1, ttt2 = k2,ttt3 = b1;
if((fMul(i,ttt1*tt+ttt3,c)+fMul(j,ttt2*tt-ttt2+1LL,c))%c!=)
{
flag = ;
break;
}
}
if(flag)
{
printf("%d %d\n",i,j);
flag1=;
}
}
if(!flag1)
printf("-1\n");
}
}

HDU 5478 Can you find it 随机化 数学的更多相关文章

  1. 2015上海网络赛 HDU 5478 Can you find it 数学

    HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...

  2. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  3. HDU 5478 Can you find it(数学问题)

    题目大意: 给你  ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...). 要求所有的n都满足上述的式子. 问这样的a,b 有多少对?   分析这个问题 ...

  4. hdu 4739 Zhuge Liang's Mines 随机化

    Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  5. HDU 2080 夹角有多大II (数学) atan(y/x)分类求角度

    夹角有多大II Problem Description 这次xhd面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小.注:夹角的范围[0,180],两个点不会在圆心出现. ...

  6. HDU 2050 【dp】【简单数学】

    题意: 中文. 思路: 不难发现数学规律是这样的,每次增加的划分区域的数量是每次增加的交点的数量再加一.然后就总结出了递推公式. #include<stdio.h> ]; int main ...

  7. 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...

  8. HDU 5063 Operation the Sequence(暴力 数学)

    题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...

  9. HDU 6242 Geometry Problem(计算几何 + 随机化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...

随机推荐

  1. pku,杨建武:文本挖掘技术

    http://webkdd.org/course/ http://www.icst.pku.edu.cn/lcwm/course/WebDataMining/ http://www.icst.pku. ...

  2. Microsoft强大团队(源代码)管理工具--TFS2010 与vs结合

    今天看了与vs 集成原理工具 TFS 2010, 角色分配.项目管理.开发源代码管理.任务分配管理.测试文档管理及跟踪等管理流程.代码版本的分支与合并等等,功能好强大啊. 以下将其安装配置简要介绍(以 ...

  3. RPi 2B 中文语言包

    /************************************************************************* * RPi 2B 中文语言包 * 声明: * 本文 ...

  4. 用TIMESTAMP类型取代INT和DATETIME

    时间在我们开发中应用非常普遍,大部分开发中我们将用Mysql的datetime格式来存储,但是对于经常用时间来排序或者查询的应用中,我们要将时间做成索引,这个就跟查询效率很有关系,但是很多程序员会用i ...

  5. 前端的小Demo——涉及keyCode

    以下是我的代码: <!doctype html> <html> <head> <meta charset="utf-8"> < ...

  6. 20个非常绚丽的 CSS3 特性应用演示

    这篇文章收集了20个非常绚丽的 CSS3 效果应用演示,这些示例演示了 CSS3 各种新特性的强大能力.随着越来越多的浏览器对 CSS3 支持的不断完善,设计师和开发者们有了更多的选择,以前需要使用  ...

  7. spring exception--No unique bean of type

    今天碰到一个问题,就是我现有项目需要加一个定时器任务,我的代码如下: <!-- 每日数据同步 总数监测任务******************begin --> <bean id=& ...

  8. android和ios的系统特性区别

    1.  删除:android是长按,ios为滑动/或者进入编辑模式 2.  android:应用内返回键,保证用户停留在应用程序中:硬件返回键可以让用户退出应用程序 3.  剪切/粘贴/选择等文本操作 ...

  9. 430flash的操作

    大概印象:430的flash好像有点像arm的flash,只不过是arm的flash要比430的大很多,而且430的flash不同于E2PROOM,这一点需要值得注意 MSP430flash的基本特点 ...

  10. [tensorflow in a nutshell] tensorflow简明教程 (第一部分)

    原文链接: https://medium.com/@camrongodbout/tensorflow-in-a-nutshell-part-one-basics-3f4403709c9d#.31jv5 ...