Problem A: [noip2016十连测第五场]simple(模拟)

来源:互联网 发布:unity3d粒子特效教程 编辑:程序博客网 时间:2024/06/02 05:30

Problem A: [noip2016十连测第五场]simple

Time Limit: 10 Sec  Memory Limit: 233 MB
Submit: 19  Solved: 9
[Submit][Status][Web Board]

Description

完整试题详见:http://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf
对于给定正整数 n,m,我们称正整数 c 为好的,当且仅当存在非负整数 x,y,使得 n*x+m*y=c。现在给出多组数
据,对于每组数据,给定 n,m,q,求[1,q]内有多少个正整数不是好的。

Input

第一行,一个整数 T 表示数据组数。
接下来每行三个数,分别表示 n,m,q, 即一组询问。
n≤10^5, m≤10^9, q≤10^18, T≤10

Output

对于每组数据,输出一行表示答案。

Sample Input

278 100 470 3 34

Sample Output

423

HINT

[Submit][Status]

题解:模拟

nx+my=c其实可以看做通过走n步x,m步y所能到达的所有高度。

f[i]表示通过只走y长度在对x取模的情况下等于i时的最小高度。求出f[i]后就可以计算出还能再走多少个x,ans+=(h-f[i])/x+1.类似于洛谷月赛跳楼机那个题。

#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#define N 200003#define LL long longusing namespace std;LL n,m,h,f[N];int main(){freopen("a.in","r",stdin);freopen("my.out","w",stdout);int t=0;scanf("%d",&t);for (int i=1;i<=t;i++){  scanf("%I64d%I64d%I64d",&n,&m,&h);  memset(f,-1,sizeof(f));  f[0]=0; LL last=0;  for (int j=1;f[(last+m)%n]==-1;j++)   f[(last+m)%n]=f[last]+m,last=(last+m)%n;  LL ans=0;  for (int i=0;i<n;i++)   if (f[i]!=-1&&f[i]<=h) ans+=(h-f[i])/n+1;  printf("%I64d\n",h-ans+1);    }}



0 0