lightoj 1014 数论

来源:互联网 发布:淘宝售后服务流程图 编辑:程序博客网 时间:2024/05/23 21:44

就是求p-l有多少个大于l的因子

暴力即可

AC代码如下:

#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int num[5000000], cnt;int main(){    int T, P, L, Case = 1;    scanf( "%d", &T );    while( T-- ){        scanf( "%d%d", &P, &L );        int flag = 0;        printf( "Case %d:", Case++ );        cnt = 0;        for( int i = 1; i <= sqrt( P - L ); i++ ){            if( ( P - L ) % i == 0 ){                num[cnt++] = i;                if( i > L || ( P - L ) / i > L ){                    flag = 1;                }            }        }        if( !flag ){            printf( " impossible\n" );        }else{            for( int i = 0; i < cnt; i++ ){                if( num[i] > L ){                    printf( " %d", num[i] );                }            }            if( ( P - L ) / num[cnt-1] == num[cnt-1] ){                cnt--;            }            for( int i = cnt - 1; i >= 0; i-- ){                if( ( P - L ) / num[i] > L ){                    printf( " %d", ( P - L ) / num[i] );                }            }            printf( "\n" );        }    }    return 0;}


0 0
原创粉丝点击