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 && ...
随机推荐
- MAX-HEAPIFY(2/3n的疑惑)
Q: In CLRS, third Edition, on page 155, it is given that in MAX-HEAPIFY, The children’s subtrees eac ...
- 使用JRockit进行性能优化一:环境搭建
1. jrockit简介 jrockit前身是BA jrockit,后被oracle收购,并免费发布,但并不开源. jrockit可以看做是兼容标准的JDK基础上的JVM,同原有的JVM相比, ...
- windows ssh RPi 2B
/************************************************************************* * windows ssh RPi 2B * 声明 ...
- Go语言项目的错误和异常管理 via 达达
Go语言项目的错误和异常管理 最近连续遇到朋友问我项目里错误和异常管理的事情,之前也多次跟团队强调过错误和异常管理的一些概念,所以趁今天有动力就赶紧写一篇Go语言项目错误和异常管理的经验分享. 首先我 ...
- 【转】Linux(Ubuntu)下面SecureCRT 完全破解
仅供测试, 勿用作商业用途.首先要到vandyke网站下载一个securecrt, 需要注册.http://www.vandyke.com/download/securecrt/download.ht ...
- sublime3安装python插件 -- SublimeCodeIntel
先装Package Control,类似pip的一个索引安装工具. 1.http://sublime.wbond.net/Package%20Control.sublime-package 2.sub ...
- Java8 Stream API
Stream是Java8中,操作集合的一个重要特性. 从iteration到Stream操作 当你操作一个集合的时候,你通常的做法是迭代每一个元素,然后处理你想要的事情.举个例子: String co ...
- 房租管理小软件(四):对linq的使用
1.对LInq的封装如下: private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMap ...
- 设计模式_Proxy_代理模式
形象例子: 跟MM在网上聊天,一开头总是“hi,你好”,“你从哪儿来呀?”“你多大了?”“身高多少呀?”这些话,真烦人,写个程序做为我的Proxy吧,凡是接收到这些话都设置好了自动的回答,接收到其他的 ...
- Ajax解决缓存的5种方法
原文:http://www.ido321.com/129.html 1.在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″ ...