HDU 5478 Can you find it 随机化 数学
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就好了
@)1%KBO0HM418$J94$1R.jpg)
代码:
//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 随机化 数学的更多相关文章
- 2015上海网络赛 HDU 5478 Can you find it 数学
HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- HDU 5478 Can you find it(数学问题)
题目大意: 给你 ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...). 要求所有的n都满足上述的式子. 问这样的a,b 有多少对? 分析这个问题 ...
- 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 ...
- HDU 2080 夹角有多大II (数学) atan(y/x)分类求角度
夹角有多大II Problem Description 这次xhd面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小.注:夹角的范围[0,180],两个点不会在圆心出现. ...
- HDU 2050 【dp】【简单数学】
题意: 中文. 思路: 不难发现数学规律是这样的,每次增加的划分区域的数量是每次增加的交点的数量再加一.然后就总结出了递推公式. #include<stdio.h> ]; int main ...
- 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...
- HDU 5063 Operation the Sequence(暴力 数学)
题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...
- HDU 6242 Geometry Problem(计算几何 + 随机化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...
随机推荐
- hibernate实体的几种状态:
hibernate实体的几种状态: 实体的生命周期中,实体主要经过瞬时(Transient),托管(Attatched或Managed),游离(Detached)和销毁(Removed)四个状态. 瞬 ...
- UVa 1605 (构造) Building for UN
题意: 有n个国家,要设计一栋长方体的大楼,使得每个单位方格都属于其中一个国家,而且每个国家都要和其他国家相邻. 分析: 紫书上有一种很巧妙的构造方法: 一共有2层,每层n×n.一层是每行一个国家,另 ...
- 嵌入式linux市场份额
来自华清远见2014年度的调查统计数据显示,在嵌入式产品研发的软件开发平台的选择上,嵌入式Linux以55%的市场份额遥遥领先于其他嵌入式开发软件发平台,比去年增长了13个百分比,这已经是连续4年比例 ...
- Spring MVC 教程
目录 一.前言二.spring mvc 核心类与接口三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说明 ...
- 让Codeigniter控制器支持多级目录
<?php if (!defined('BASEPATH')) { exit ('No direct script access allowed');} class MY_Router exte ...
- 实现sqrt()函数
求一个正数N的开方, 并且可以指定精度, 要求不能用库函数sqrt 方法一:如下所示,先求sqrt(N)的整数部分,再求小数点后1位,2位 ... ... 方法二:牛顿迭代法,根据公式 Ai+1 = ...
- class属性添加多个类
<html> <head> <style type="text/css"> h1.intro { color:blue; text-align: ...
- C#中如何截取Windows消息来触发自定义事件
原文 C#中如何截取Windows消息来触发自定义事件 在c#windows开发中,我们常常会遇到拦截windows消息,来触发某个特定任务的问题. 由于目前使用c#的开发人员非常多,而且大多数c#程 ...
- Java中调用参数是数组的存储过程
Java中调用参数是数组的存储过程 1. 存储过程以及类型定义如下: --The array in oracle CREATE OR REPLACE TYPE idArray AS TABLE OF ...
- static用法详解
一. 面向过程程序设计 1.静态全局变量 在全局变量前,加上关键字static,该变量就被定义成为一个静态全局变量.我们先举一个静态全局变量的例子,如下: //Example 1 #include & ...